小编Mon*_*gal的帖子

Get key value irrespective of depth in array of object

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

0
推荐指数
1
解决办法
41
查看次数

标签 统计

javascript ×1