how to use for loop with objectt code example
Example 1: javascript loop through object
let obj = { first: "John", last: "Doe" };
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
for (const key of Object.keys(obj)) {
console.log(key, obj[key]);
}
Object.entries(obj).forEach(
([key, value]) => console.log(key, value)
);
Example 2: loop key in object
const fruits = { apple: 28, orange: 17 }
for(key in fruits){
console.log(key)
}
Example 3: for in loop javascript
var person = {"name":"taylor","age":31};
for (property in person) {
console.log(property,person[property]);
}