js遍历json对象数组的key和value

/**
 * 获取某一个json对象的某一行某一个keyvalue */
function getValueByKey (thekey, node){
    for(var key in node) {
        if (key == thekey) {
            return node[key];
        }
    }
    return null;
}

/**
 * 获取某一个json对象数组的某一行某一个keyvalue */
function getValueByKeyArray (thekey, nodes ,row){
    if(nodes.length == 0){
        return null;
    }
    for(var i = 0;i < nodes.length;i++){
        if(i == row){
            for(var key in nodes[i]){
                if( key == thekey){
                    return nodes[i][key];
                }
            }
        }
     }
     return null;
}


猜你喜欢

转载自blog.csdn.net/blossomfzq/article/details/80826172