how to iterate through a js object code example
Example 1: js loop through object
for (var property in object) {
if (object.hasOwnProperty(property)) {
}
}
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];
}
Example 3: going through every attributes of an object javascript
let a = {x: 200, y: 1}
let attributes = Object.keys(a)
console.log(attributes)