Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json get key names as text?

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.

like image 707
Hailwood Avatar asked Nov 19 '10 06:11

Hailwood


1 Answers

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]);
like image 65
DanneManne Avatar answered Nov 13 '22 09:11

DanneManne