Enter the depth of the attribute, and the value of the output attribute

has the following object:
requires the input attribute and the depth of this attribute, and outputs the value corresponding to this attribute
Why can"t you enter the attribute directly, because the name may be duplicated? the outermost Status in the JSON above and Status under Result have the same name

.

findValue (key,depth)

{
    "Status":"200",
    "Message":"",
    "OrderNumber":null,
    "Result":{
        "Partners":[
            {
                "StockName":"xx",
                "StockType":"",
                "StockPercent":"49.1900%",
                "ShouldCapi":"491.900000"
            }

        ],
        "Employees":[
            {
                "Name":"xx",
                "Job":""
            },
            {
                "Name":"xx",
                "Job":""
            }
        ],
        "Branches":[
            {
                "CompanyId":"8dc057af59e908b6a1c05d74de114134",
                "RegNo":"500902300083458",
                "Name":"",
                "BelongOrg":"",
                "CreditCode":null,
                "OperName":"xx"
            }
        ],
        "ChangeRecords":[
            {
                "ProjectName":"",
                "BeforeContent":";",
                "AfterContent":";",
                "ChangeDate":"2017-07-21T00:00:00+08:00"
            }
        ],
        "ContactInfo":{
            "WebSite":[
                {
                    "Name":null,
                    "Url":"www.xiaojukeji.com"
                }
            ],
            "PhoneNumber":"010-83043726",
            "Email":"zhangyimei@diditaxi.com.cn"
        },
        "Industry":{
            "Industry":"",
            "SubIndustry":""
        },
        "KeyNo":"4659626b1e5e43f1bcad8c268753216e",
        "Name":"",
        "No":"110108015068911",
        "BelongOrg":"",
        "OperName":"",
        "StartDate":"2012-07-10T00:00:00+08:00",
        "EndDate":null,
        "Status":""
    }
}

such as

findval ("Partners", 2) output

[{
    "StockName":"xx",
    "StockType":"",
    "StockPercent":"49.1900%",
    "ShouldCapi":"491.900000"
    }
]

findVal ("WebSite", 3) output

[{
    "Name":null,
    "Url":"www.xiaojukeji.com"
}],

findVal ("WebSite", 3) output

Apr.11,2021

the following function usage findVal ("WebSite", 3, obj) where obj is the object you are looking for and returns an array containing all the values that meet the criteria.

/**
*keyname: 
*layer: 
*obj: 
*cLayer: 
*/
function findVal(keyname, layer, obj, cLayer) {
    var result = [];
    var currentLayer = cLayer || 1;
    var objType = typeof obj;
    if(currentLayer > layer 
        || objType === "string"
        || objType === "number" 
        || obj === null
        || obj === undefined) {
        return result;
    }

    for(var key in obj) {
        if(key == keyname && currentLayer == layer) {
            result.push(obj[key]);
        }
        var f = find(keyname, layer, obj[key], currentLayer + 1);
        if(f && f.length > 0) {
            result.push(...f);
        }
    }
    return result;
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eba14e-4856d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eba14e-4856d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?