I am facing an issue where I have an array and I need to transform it into an array of its children elements.
var data = [{
name: 'Cars',
content: 'BMW',
value: 2000
},
{
name: 'Cars',
content: 'Fiat',
value: 542
},
...
]
The desired end result should look like this:
[
{
name: "Children Array",
children: [
{
name: "Cars",
children: [
{
name: "BMW",
value: 2000
},
...
]
},
...
]
}
]
This is what I have done so far:
// JavaScript code goes here
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
I am struggling with implementing the second layer of children. Any suggestions or advice would be greatly appreciated.