javascript iterate over keys and values of object code example
Example 1: javascript iterate object key values
Object.entries(obj).forEach(([key, value]) => {
console.log(key, value);
});
Example 2: 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];
}