I have this array
, I want to reduce it and get a new one array
that contains only the field c_docu
:
var array = [
{"c_docu": "00", "n_docu": "0102556", "l_agen": "MONTALVO MEZA NORMA"},
{"c_docu": "00", "n_docu": "0102558", "l_agen": "SOTO CUEVA OSCAR OBID"},
{"c_docu": "00", "n_docu": "0102564", "l_agen": "QUISPE RAMOS MARGARITA"},
{"c_docu": "00", "n_docu": "0102563", "l_agen": "SALVADOR ORIHUELA CASILDA M."},
{"c_docu": "00", "n_docu": "0102875", "l_agen": "TAYPE QUISPE ISENIA"},
{"c_docu": "00", "n_docu": "0102880", "l_agen": "DE LA CRUZ TAIPE JULIA"},
{"c_docu": "00", "n_docu": "0102626", "l_agen": "GOBIERNO REGIONAL JUNIN"},
{"c_docu": "00", "n_docu": "0102697", "l_agen": "TAYPE DE LA CRUZ MAGNO"},
{"c_docu": "00", "n_docu": "0102512", "l_agen": "PEREZ QUISPE, ESTANES VICTOR"},
{"c_docu": "00", "n_docu": "0100088", "l_agen": "ALIAGA LAURA JAVIER"}
]
this is the result i want to get
var array2 = [
"0102556",
"0102564",
"0102563",
"0102875",
"0102880",
"0102626",
"0102697",
"0102512",
"0100088"
]
To do what you need, the map method is perfect for you
In short, what the method does
map
is extract the information you need and create a newarray
one with only the desired values.What you need is to reduce objects within an array actually, and as @Paulo said it
.map
's exactly what you need, I would just add that to reduce individual objects, assignment by destructuring would make it even shorter: