I’ve got a deep nested JavaScript Object and I know a value which is at the object’s lowest position. I want to know the parent key and grandparent key.
I set up a jsbin https://jsbin.com/yimugezuxe/edit?js,console
Based on the value 'uniqueID#9aserdf' I want to know/return its parent keys: 'Stage 2' and 'Level 2' from the object below:
const obj = {
"Level 1": {
"Stage 1": [
{
"title": "Parent 1",
"id": "Parent1#id",
"Children": [
{
"title": "Steve",
"id": "uniqueID1"
},
{
"title": "James",
"id": "uniqueID#9"
}
]
}
]
},
"Level 2": {
"Stage 1": [
{
"title": "Parent 4",
"id": "Parent4#id",
"Children": [
{
"title": "Tim",
"id": "uniqueIDadsf"
},
{
"title": "Hans",
"id": "uniqueID#9asdf"
}
]
}
],
"Stage 2": [
{
"title": "Parent 10",
"id": "Parent10#id",
"Children": [
{
"title": "Chris",
"id": "uniqueIDadsf33"
},
{
"title": "Jack",
"id": "uniqueID#9aserdf"
}
]
}
]
}
};
// based on the value 'uniqueID#9aserdf' I want to know/return its parent keys: 'Stage 2' and 'Level 2'