I have an array of objects in which I would like to merge all objects into a single object.
For example:
arrObj = [{
"id1": {
"subId1": {
"data1": 10
}
},
"id2": {
"subId1": {
"data1": 20
}
}
},
{
"id1": {
"subId1": {
"data2": 20
}
},
"id2": {
"subId2": {
"data2": 30
}
}
}
];
Expected result:
resObj = {
"id1": {
"subId1": {
"data1": 10,
"data2": 20
}
},
"id2": {
"subId1": {
"data1": 20,
},
"subId2": {
"data2": 30
}
}
}
I tried
Object.assign({},...arrObj)
But it is not satisfying the expected result. How to merge all objects in an array of objects as the expected result