iterate through an object code example
Example 1: javascript loop through object
Object.entries(obj).forEach(
([key, value]) => console.log(key, value)
);
Example 2: javascript iterate over object
var obj = { first: "John", last: "Doe" };
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
Example 3: iterate over object javascript
const keys = Object.keys(fruits)
for (const key of keys) {
console.log(key)
}
Example 4: javascript loop through object example
var person={
first_name:"johnny",
last_name: "johnson",
phone:"703-3424-1111"
};
for (var property in person) {
console.log(property,":",person[property]);
}
Example 5: javascript iterate over object keys and values
const object1 = {
a: 'somestring',
b: 42
};
for (let [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 6: loop through object javascript
for (var property in object) {
if (object.hasOwnProperty(property)) {
}
}