javascript looping over objects code example
Example 1: javascript loop through object
Object.entries(obj).forEach(
([key, value]) => console.log(key, value)
);
Example 2: 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 3: javascript loop through object values
var myObj = {foo: "bar", baz: "baz"};
Object.values(myObj).map((val) => {
console.log(val);
})
Example 4: javascript loop through object
var person = {"name":"bob", age:45};
for (var property in person) {
console.log(person[property]);
}