I have an array of Object like
[
{
"parentId": "uniqueParentId1",
"parentName": "Parent1",
"childProp1": "test1",
"childProp2": "test3"
},
{
"parentId": "uniqueParentId2",
"parentName": "Parent2",
"childProp1": "somevals",
"childProp2": "other vals"
}
{
"parentId": "uniqueParentId2",
"parentName": "Parent2",
"childProp1": "somevals 1",
"childProp2": "other vals 1"
}
]
and I want to combine it based in parentId and create an array of Object like below in Javascript . How can I do it ?
[
{
"id": "uniqueParentId1",
"name": "Parent1",
"children": [
{
"childProp1": "test1",
"childProp2": "test3"
}
]
},
{
"id": "uniqueParentId2",
"name": "Parent2",
"children": [
{
"childProp1": "somevals",
"childProp2": "other vals"
},
{
"childProp1": "somevals 1",
"childProp2": "other vals 1"
}
]
}
]
The idea to convert flat object to nested Object is so that I can use the nested Object in Iterations easiely