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 p = {
2 0: "value1",
3 "b": "value2",
4 key: "value3"
5};
6
7for (var key of Object.keys(p)) {
8 console.log(key + " -> " + p[key])
9}
1var arr = [ "one", "two", "three", "four", "five" ];
2var obj = { one:1, two:2, three:3, four:4, five:5 };
3
4jQuery.each(arr, function() {
5 $("#" + this).text("My id is " + this + ".");
6 return (this != "four"); // will stop running to skip "five"
7});
8
9jQuery.each(obj, function(i, val) {
10 $("#" + i).append(document.createTextNode(" - " + val));
11});
1var p = {
2 "p1": "value1",
3 "p2": "value2",
4 "p3": "value3"
5};
6
7for (var key in p) {
8 if (p.hasOwnProperty(key)) {
9 console.log(key + " -> " + p[key]);
10 }
11}
1import org.json.JSONObject;
2
3public static void printJsonObject(JSONObject jsonObj) {
4 for (String keyStr : jsonObj.keySet()) {
5 Object keyvalue = jsonObj.get(keyStr);
6
7 //Print key and value
8 System.out.println("key: "+ keyStr + " value: " + keyvalue);
9
10 //for nested objects iteration if required
11 //if (keyvalue instanceof JSONObject)
12 // printJsonObject((JSONObject)keyvalue);
13 }
14}
15
1let a = {x: 200, y: 1}
2let attributes = Object.keys(a)
3console.log(attributes)
4//output: ["x", "y"]