how to iterate through object keys 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 iterate through object attributes

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

Example 4: going through every attributes of an object javascript

let a = {x: 200, y: 1}
let attributes = Object.keys(a)
console.log(attributes)
//output: ["x", "y"]