how to iterate over object code example

Example 1: javascript loop through object

Object.entries(obj).forEach(
    ([key, value]) => console.log(key, value)
);

Example 2: js loop over object

const object = {a: 1, b: 2, c: 3};

for (const property in object) {
  console.log(`${property}: ${object[property]}`);
}

Example 3: javascript loop through object

var p = {
    "p1": "value1",
    "p2": "value2",
    "p3": "value3"
};

for (var key in p) {
    if (p.hasOwnProperty(key)) {
        console.log(key + " -> " + p[key]);
    }
}

Example 4: javascript loop through object

for (var property in object) {
  if (object.hasOwnProperty(property)) {
    // Do things here
  }
}

Example 5: javascript loop object

for (let thisVariable in thisObject)

Example 6: iterate over array of object javascript and access the properties

for (let item of items) {
    console.log(item); // Will display contents of the object inside the array
}