I’m confused to merge array contents from JavaScript.
Please help to get the best way to get desired result. A i also have tried other ways referred on SO.
[
{
"Afghanistan": 2646432,
"categories": "2018"
},
{
"Afghanistan": 6545700,
"categories": "2019"
},
{
"Afghanistan": 7475886,
"categories": "2020"
},
{
"Albania": 740232,
"categories": "2018"
},
{
"Albania": 2374785,
"categories": "2019"
},
{
"Albania": 2180850,
"categories": "2020"
}
]
This was my expected output::
[ { "Afghanistan": 2646432, "Albania": 740232, "categories": "2018" }, { "Afghanistan": 6545700, "Albania": 2374785, "categories": "2019" }, { "Afghanistan": 7475886, "Albania": 2180850, "categories": "2020" } ]
2
Answers
You can use reduce method