Upon filtering the data, the response obtained inside the findChildrens
function is as follows:
My expectation now is that if the object length of this.newRegion
is greater than 1, then merge the children of the second object into the parent object's children.
For example - From the given response, there are two objects "Africa"
and "Europe"
. Therefore, I want to combine the children of "Europe"
with the parent children of "Africa"
.
Could anyone assist me in achieving the desired output?
findChildrens(){
this.newRegion = [
{
"name": "Africa",
"children": [
{
"name": "Test1",
"region": "1UL Africa"
},
{
"name": "Test2",
"region": "South Africa",
},
{
"name": "Test3",
"region": "New Test",
}
]
},
{
"name": "Europe",
"children": [
{
"name": "Test4",
"region": "1UL Africa"
},
{
"name": "Test5",
"region": "Test Europe"
}
]
}
];
};
};
Expected Result
this.newRegion = [
{
"name": "Africa",
"children": [
{
"name": "Test1",
"region": "1UL Africa"
},
{
"name": "Test2",
"region": "South Africa",
},
{
"name": "Test3",
"region": "New Test",
},
{
"name": "Test4",
"region": "1UL Africa"
},
{
"name": "Test5",
"region": "Test Europe"
}
]
}
];
};