I have an array of objects in which I want to get the value of a key for e.g. 'variable'. But the depth of the key is varying, like it could be as follows -
[{
"test": {
"nameObj": {
"name": "DateExpires",
"title": "DateExpires",
"variable": "DateTime"
},
}
},
{
"test": {
"nameObjSomethingElse": {
"name": "DateExpires",
"title": "DateExpires",
"variable": "DateTime"
},
}
},
{
"test": {
"nameObjSomethingElse": {
"name": "DateExpires",
"title": "DateExpires",
"anotherLevel": {
"variable": "DateTime"
}
}
}
}] …Run Code Online (Sandbox Code Playgroud) javascript ×1