xxxxxxxxxx
const person = {
name: 'name',
age: 30,
hobbies: ['Baseball', 'Woodworking']
}
for (const hobby of person.hobbies) {
console.log(hobby)
}
xxxxxxxxxx
// `for...of` loop
for (const [key, value] of Object.entries(animals)) {
console.log(`${key}: ${value}`);
}
// `forEach()` method
Object.entries(animals).forEach(([key, value]) => {
console.log(`${key}: ${value}`)
});
xxxxxxxxxx
const obj = { foo: 'bar', baz: 42 };
Object.entries(obj).forEach(([key, value]) => console.log(`${key}: ${value}`)); // "foo: bar", "baz: 42"
xxxxxxxxxx
const fruits = { apple: 28, orange: 17 }
for(key in fruits){
console.log(key)
}