iterate through object values javascript code example
Example 1: 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 2: javascript loop through object
for (var property in object) {
if (object.hasOwnProperty(property)) {
}
}
Example 3: javascript loop through object values
var myObj = {foo: "bar", baz: "baz"};
Object.values(myObj).map((val) => {
console.log(val);
})
Example 4: javascript looping through object
for (var property in object) {
if (object.hasOwnProperty(property)) {
}
}
Example 5: javascript looping through object
for (const [fruit, count] of entries) {
console.log(`There are ${count} ${fruit}s`)
}