Solved: change one format to another format of the array of objects

Question:

I have the main three parameters that are important category, subcategory, and group
This is an array of objects and I want to change the format of this array
Like all data divide into category inside sub-category inside group wise data I want
The expected result looks like this
If the category match data push into the match subcategory if not then create a category for the same and if the subcategory match push into that one otherwise create a new one same as the group if the group match into subcategory then push otherwise create one
Like I want hierarchy like category => subcategory => group
And I try the this code

Best Answer:

does this helps?


If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com