for loop get property array javascript code example

Example 1: javascript loop through object

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

Example 2: loop an object properties in ts

Object.keys(obj).forEach(e => console.log(`key=${e}  value=${obj[e]}`));

Example 3: javascript iterate through object attributes

for (var prop in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, prop)) {
        // do stuff
    }
}

Example 4: 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
}