I am trying to combine objects inside an array using reduce my object looks like bellow and has the fallowing structure.
[
{
"AREA": [
"EMAC"
],
"SUPER_REGION": [
"South East Europe Region",
"East Europe Region",
],
},
{
"AREA": [
"CCA"
],
"SUPER_REGION": [
"Taiwan",
"China Hong Kong"
],
}
]
Expected output :
{
"AREA": [
"EMAC","CCA"
],
"SUPER_REGION": [
"South East Europe Region",
"East Europe Region",
"Taiwan",
"China Hong Kong"
],
}
My current code using reduce :
let sum = finalval.reduce(function (accumulator, { AREA, SUPER_REGION }) {
accumulator["AREA"] += AREA;
return accumulator;
}, {});
the above code returns me output by combining the values into one string but I want them to be split and added into a single object like shown in expected output. How can i actually push values into these object like we do on arrays using push method ?