iterate object properties javascript code example

Example 1: loop an object properties in ts

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

Example 2: js loop through object

const obj = { a: 1, b: 2 };

Object.keys(obj).forEach(key => {
	console.log("key: ", key);
  	console.log("Value: ", obj[key]);
} );

Example 3: javascript loop through object

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

Example 4: javascript iterate through object attributes

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