I am trying to display an array of key value pair, but couldn't code it properly.
var result =new Array( {'id' : 1}, {'id' : 2} );
$.each($.parseJSON(result), function(k, v) {
alert(k + ' is ' + v);
});
Here is the Fiddle links.
I am trying to display an array of key value pair, but couldn't code it properly.
var result =new Array( {'id' : 1}, {'id' : 2} );
$.each($.parseJSON(result), function(k, v) {
alert(k + ' is ' + v);
});
Here is the Fiddle links.
I changed your code as below:
var result =[ {'id' : 1}, {'id' : 2} ];
$.each(result, function(k, v) {
alert("id" + ' is ' + v.id);
});
According to your comments, here is the updated code:
var result =[ {'id' : 1}, {'id' : 2} ];
$.each(result, function(k, v) {
for(var prop in v){
if(v.hasOwnProperty(prop)){
alert(prop + ' is ' + v[prop]);
}
}
});
Try this.
var result =[ {'id' : 1}, {'id' : 2} ];
$.each(result, function(k, v) {
for(var prop in v){
alert(k + ' is ' + prop);
}
});
var result =new Array( {'id' : 1}, {'id' : 2} );
$.each(result, function(key, value){
$.each(value, function(key, value){
alert(key+' : '+value);
});
});