Tuesday, April 21, 2015

Jquery iterate through json array with for loop

var arr = [{ "id": "10", "class": "child-of-9" }, { "id": "11", "classd": "child-of-10" }];

for (var i = 0; i < arr.length; i++) {

var obj = arr[i];



console.log(obj);

for (var key in obj) {

var attrName = key;

var attrValue = obj[key];

console.log('attrName -' + attrName + '- attrValue -' + attrValue);



}

}


No comments:

Post a Comment