Is there a short way to re-assign array that consists of objects into a new one. I want to use Lodash library and can't figure out how to split it inside and concatenate. I need this to build a tree using jstree library
I have something like this:
[
{
'text':'parent 1',
'children': [
{
'text':'children 3'
}
]
},
{
'text':'parent 2',
'children': []
},
{
'text':'parent 3',
'children': []
},
{
'text':'parent 1',
'children': [
{
'text':'children 1',
'children': []
},
{
'text':'children 2',
'children': []
}
]
}
]
And I want to have the next after transforming
[
{
'text':'parent 2',
'children': []
},
{
'text':'parent 3',
'children': []
},
{
'text':'parent 1',
'children': [
{
'text':'children 1',
'children': []
},
{
'text':'children 2',
'children': []
},
{
'text':'children 3'
}
]
}
]
And I want to combine all objects if 'text' is the same and concatenate their children.
The nested level may be as much as possible, no restriction.
[
{
'text':'parent 1',
'children': [
{
'text':'children 2',
'children': [
{
'text':'parent 3',
'children': [
{
'text':'parent 4',
'children': [
...
]
},
]
},
]
}
]
}
]
Is it possible?