最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - json get key names as text? - Stack Overflow

programmeradmin5浏览0评论

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('key: rows[i][j].key', 'value: ',rows[i][j]);
    }
}

or whatever so I can access the key.

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('key: rows[i][j].key', 'value: ',rows[i][j]);
    }
}

or whatever so I can access the key.

Share Improve this question asked Nov 19, 2010 at 6:22 HailwoodHailwood 92.6k112 gold badges273 silver badges425 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 14

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)

  1. 暂无评论