I have the "concept" array from which I am interested in obtaining the values of the l_prod field, and passing said values to the map function to my other "data" array.
I have tried to do it in the following way, but it does not work for me... I hope I have made it clear and you can help me, thanks in advance.
const concept = [{"c_prod":"000004","l_prod":"FAENAS"},
{"c_prod":"000005","l_prod":"MULTAS"}];
const datos = [
{"n_docu":"23248169","l_agen":"USUARIO","FAENAS":"1.00","MULTAS":"0.00"},
{"n_docu":"71377558","l_agen":"SIMEON","FAENAS":"5.00","MULTAS":"1.00"},
{"n_docu":"46117631","l_agen":"EGUAVIL","FAENAS":"0.00","MULTAS":"1.00"}
];
var resp = [];
concept.forEach(function(c,i) {
var l_prod = c.l_prod;
resp.push(datos.map(d => d.l_prod));
});
console.log(resp);
RESULT I WANT TO OBTAIN
[ ["1.00", "5.00", "0.00"],["0.00", "1.00", "1.00"]]
The problem you have is that you can't use dot notation on the value of a variable.
The statement
d.l_prod
is literally returning the value of the"l_prod"
object 's keyd
. Sinced
it doesn't have that key, it returnsundefined
.To get what you need you must do it with the following syntax
This way you achieve what you want, accessing the key
"FAENAS"
or"MULTAS"
or whatever value itl_prod
may have.Additionally, you can simplify the solution by using dos
map
.I leave you the complete example.
I hope it works.