javascript loop over object properties code example

Example 1: loop an object properties in ts

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

Example 2: javascript iterate object

let person={
 	first_name:"johnny",
  	last_name: "johnson",
	phone:"703-3424-1111"
};
for (let i in person) {
  let t = person[i]
  	console.log(i,":",t);
}

Example 3: 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 4: js loop over object

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

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

Example 5: javascript loop through object properties

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