I have a success function that gets an object:
success: function(json) {
}
json is [>Object , >Object , >Object, ...]
inside each object i have some keys and values:
object[
test: yes
testing: no
]
i am trying to get those values and the keys and place them in a div element:
for ( var object in json)
{
for ( var objects in json[object])
{
var obj = jQuery.parseJSON(json[object][objects]);
$('#details').append(obj);
}
}
this will give me all values from all objects one after each other mashed together. I want to be able to know the keys also so i can arrange them a bit in a table or something any ideas?
Looks like you have it done already,
objectsshould be the keys:Here is a jsfiddle to demonstrate: http://jsfiddle.net/jasper/FmDU9/1/
On a side-note:
for ( var i = 0; i < len; i++){is much faster thanfor ( var object in json)so if you are iterating through an array of objects, usefor ( var i = 0; i < len; i++){to iterate through the array. Here is some proof of this: http://jsperf.com/for-in-tests/2