I was faced with the question of building a tree from a flat array. We have an array.
[
{
"h1": "h001",
"h2": "z001"
},
{
"h1": "h002",
"h2": "z002"
},
{
"h1": "h003",
"h2": "z003"
}
]
I would like to get something like this:
[{
"h1": "h001",
"h2": "z001",
"children": {
"h1": "h002",
"h2": "z002",
"children": {
"h1": "h003",
"h2": "z003"
}
}
}]
Is there a way to implement this?
Thanks!