Let's assume I have an array as following:
[
{
"name": "list",
"text": "SomeText1"
},
{
"name": "complex",
"text": "SomeText2",
"config": {
"name": "configItem",
"text": "SomeText3",
"anotherObject": {
"name": "anotherObject1",
"text": "SomeText4"
}
}
}
]
I am using this awesome code to get all Objects with a certain key (http://techslides.com/how-to-parse-and-search-json-in-javascript). In my example it is getObjects(data,'text','')
which will return all nodes as Object due to the appearance of text as key.
My only problem is, that I need to know the location of the returned Object in the whole array.
Is there any way to get it? Or at least the depth of the object in conjunction to the array?
getObjects(r,'text','')[0]
(name = list) -> depth 1
getObjects(r,'text','')[1]
(name = complex) -> depth 1
getObjects(r,'text','')[2]
(name = configItem) -> depth 2