开发者

json get key names as text?

开发者 https://www.devze.com 2023-01-25 17:25 出处:网络
I would like to find out the key of a json value. I am doing for(var i in rows){ for(var j in rows[i]){ console.log(\'value: \', rows[i][j]);

I would like to find out the key of a json value.

I am doing

for(var i in rows){
    for(var j in rows[i]){
        console.log('value: ', rows[i][j]);
    }
}

However I want to be able to do something like

for(var i in rows){
    for(var j in rows[i]){
        console.log('k开发者_运维问答ey: rows[i][j].key', 'value: ',rows[i][j]);
    }
}

or whatever so I can access the key.


When you use the syntax for(var i in rows) i is actually the key so you should be able to do:

console.log('key: ',j, ' value: ',rows[i][j]);
0

精彩评论

暂无评论...
验证码 换一张
取 消