I received the following response and I need to reorganize all the data and its children based on the buSubRegion
that is currently nested within the children. Additionally, I need to add the buSubRegion
outside of the children.
For example: In the response below, 1UL Africa
belongs to the Africa object and is also present within the Europe object, so I want to merge the children of all objects related to 1UL Africa
into one array of objects.
If a buSubRegion has the same value and is present in multiple objects, then I need to find all those objects and merge them into one.
Also, Agbara - Savoury
does not have a BU sub-region so I do not want to include this object.
Can someone please help me achieve this?
const data = [
...
];
Below is the expected output:
[
...
];