I have a json object, which needs to be iterated, I can make use of iteration as a function but wanted to see if there is a simpler way to do so. Object is as shown below:
obj = [
{
name: 'FolderA',
child: [
{
name: 'FolderB',
child: [
{
name: 'FolderC0',
child: [],
},
{
name: 'FolderC1',
child: [],
}
]
}
],
},
{
name: 'FolderM'
child: []
}
]
On some event I get level, like
level = "0-0-1"
Which I split to get [0, 0, 1] Meaning, 0th index, nested 0th index and further nested 1st index, which I get like:
obj[0][0][1],
But since nested structure depth is unknown I want the above to be generated dynamically, something like this:
obj + [0] + .children[0] + .children[1],
Not sure if this can be done, but if there is, please let me know, else I will have to use recursive function. Thanks
json.