I have 2 arrays structured like this:
let dataA = [{"id": "a1", "name": "Alpha"}, {"id": "a2", "name": "Beta"}, {"id": "a3", "name": "Gamma"}, {"id": "a4", "name": "Delta"}, {"id": "a5", "name": "Omega"}]
and
let dataB = [{"a1": 0, "a2": 100000, "a3": 500000, "a4": 300000, "a5": 45900}]
How can I transfer values from dataB
to dataA
?
For example, how do I push the value of dataB.a4
, which is 300000
, to dataA.id == a4
?
I would like the final result to be similar to:
let result = `[{"id": "a1", "name": "Alpha", "values": 0}, {"id": "a2", "name": "Beta", , "values": 100000}, {"id": "a3", "name": "Gamma", "values": 500000}, {"id": "a4", "name": "Delta", "values": 300000}, {"id": "a5", "name": "Omega", "values": 45900}]`
Any assistance would be greatly appreciated as I have been struggling with this for days.
Thank you in advance.