JSFiddle - React, Tailwind, and code Playground
by louisbros
JavaScript
var object = {
"locations": {
"Base1": {
"title": "Thisisbase1",
"Suburb1": {
"title": "Suburb1inBase1",
"AreaA": {
"title": "TitleforAreaA",
"StreetS1": {
"title": "StreetS1title"
},
"StreetC4": {
"title": "StreetC4title"
},
"StreetB7": {
"title": "StreetB7title"
}
},
"AnotherArea": {
"title": "TitleforAreaA",
"StreetS1": {
"title": "StreetS1title"
},
"StreetC4": {
"title": "StreetC4title"
},
"StreetB7": {
"title": "StreetB7title"
}
}
},
"AnotherSuburb": {
"title": "Suburb1inBase1",
"AreaA": {
"title": "TitleforAreaA",
"StreetS1": {
"title": "StreetS1title"
},
"StreetC4": {
"title": "StreetC4title"
},
"StreetB7": {
"title": "StreetB7title"
}
},
"AnotherArea": {
"title": "TitleforAreaA",
"StreetS1": {
"title": "StreetS1title"
},
"StreetC4": {
"title": "StreetC4title"
},
"StreetB7": {
"title": "StreetB7title"
}
}
}
},
"Base2": {}
}
};
var path = ["locations", "Base1", "AnotherSuburb"];
(function search(o, a){
for(var p in o){
if(typeof o[p] === 'object' && path.indexOf(p) !== -1){
a.push(p);
if(a.join('') === path.join('')){
// match, print the title
...