1var person={
2 first_name:"johnny",
3 last_name: "johnson",
4 phone:"703-3424-1111"
5};
6for (var property in person) {
7 console.log(property,":",person[property]);
8}
1var someObj = { foo: "bar"};
2
3$.each(someObj, function(propName, propVal) {
4 console.log(propName, propVal);
5});
6
1var agents = [
2 {
3 "id": "007",
4 "agent": "James Bond"
5 },
6 {
7 "id": "006",
8 "agent": "John Wick"
9 }
10 ]
11// iterate over the JSON array
12$.each(agents , function(index, item) {
13 console.log("Agent Id: " + item.id);
14 console.log("Agent Name: " + item.agent);
15});
1$.map(mapArray, function(val, key) {
2 alert("Value is :" + val);
3 alert("key is :" + key);
4});
1//https://code.jquery.com/jquery-3.5.0.js
2
3var scores = '{ "first": { "score": 660 }, "second": { "score": 330 } }';
4
5var objkeys = $.parseJSON(scores);
6
7$.each(objkeys, function(key, value) {
8 $.each(value, function(key, value){
9 console.log(value);
10 });
11});