how to loop trough an object java script

Java
for (var property in object) {
  if (object.hasOwnProperty(property)) {
    // Do things here
  }
}
for (var property in object) {   if (object.hasOwnProperty(property)) {     // Do things here   } } // Looping through arrays created from Object.keys
const keys = Object.keys(fruits)
for (const key of keys) {
  console.log(key)
}

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

const keys = Object.keys(fruits)
console.log(keys) // [apple, orange, pear]
const fruits = {
  apple: 28,
  orange: 17,
  pear: 54,
}

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

Source

Also in Java: