loop through json object jquery code example
Example 1: javascript loop through object example
var person={
first_name:"johnny",
last_name: "johnson",
phone:"703-3424-1111"
};
for (var property in person) {
console.log(property,":",person[property]);
}
Example 2: loop json jquery
$.map(mapArray, function(val, key) {
alert("Value is :" + val);
alert("key is :" + key);
});
Example 3: jquery loop through json
var agents = [
{
"id": "007",
"agent": "James Bond"
},
{
"id": "006",
"agent": "John Wick"
}
]
$.each(agents , function(index, item) {
console.log("Agent Id: " + item.id);
console.log("Agent Name: " + item.agent);
});
Example 4: jquery loop through json
var someObj = { foo: "bar"};
$.each(someObj, function(propName, propVal) {
console.log(propName, propVal);
});