html loop through object code example

Example 1: javascript loop through object

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

Example 2: how to loop trough an object java script

// Looping through arrays created from Object.keys
const keys = Object.keys(fruits)
for (const key of keys) {
  console.log(key)
}

// Results:
// apple
// orange
// pear

Example 3: javascript loop through object properties

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

Example 4: how to loop trough an object java script

const fruits = {
  apple: 28,
  orange: 17,
  pear: 54,
}

const values = Object.values(fruits)
console.log(values) // [28, 17, 54]

Example 5: 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"]