object.entries in java code example
Example 1: javascript iterate object key values
Object.entries(obj).forEach(([key, value]) => {
console.log(key, value);
});
Example 2: javascript object entries
const object1 = {
a: 'somestring',
b: 42
}
Object.entries(object1)
.forEach(([key, value]) => console.log(`${key}: ${value}`))
Example 3: how to iterate through a js object
let object = {
x: 10,
y: 10,
z: 10
};
let keys = Object.keys(object);
key.forEach(function(key){
let attribute = object[key];
}
);
for(let key of keys){
let attribute = object[key];
}
for(let i = 0; i < keys.length; i++){
let key = keys[i];
let attribute = object[key];
}