📜  通过 json 搜索键 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:42.694000             🧑  作者: Mango

代码示例1
//return an array of values that match on a certain key
function getValues(obj, key) {
    var objects = [];
    for (var i in obj) {
        if (!obj.hasOwnProperty(i)) continue;
        if (typeof obj[i] == 'object') {
            objects = objects.concat(getValues(obj[i], key));
        } else if (i == key) {
            objects.push(obj[i]);
        }
    }
    return objects;
}