1var p = {
2 "p1": "value1",
3 "p2": "value2",
4 "p3": "value3"
5};
6
7// for-in
8for (var key in p) {
9 if (p.hasOwnProperty(key)) {
10 console.log(key + " -> " + p[key]);
11 }
12}
13
14// for-of with Object.keys()
15for (var key of Object.keys(p)) {
16 console.log(key + " -> " + p[key])
17}
18
19// Object.entries()
20for (let [key, value] of Object.entries(p)) {
21 console.log(`${key}: ${value}`);
22}
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 myObj = {foo: "bar", baz: "baz"};
2Object.values(myObj).map((val) => {
3console.log(val);
4})
5// "bar" "baz"
1const object = {a: 1, b: 2, c: 3};
2
3for (const property in object) {
4 console.log(`${property}: ${object[property]}`);
5}
1for (var prop in obj) {
2 if (Object.prototype.hasOwnProperty.call(obj, prop)) {
3 // do stuff
4 }
5}
1for (var prop in obj) {
2 if (Object.prototype.hasOwnProperty.call(obj, prop)) {
3 // do stuff
4 }
5}
6