looping through key pair javascript code example
Example 1: javascript foreach key value
myObject ={a:1,b:2,c:3}
//es6
Object.entries(myObject).forEach(([key, value]) => {
console.log(key , value); // key ,value
});
//es7
Object.keys(myObject).forEach(key => {
console.log(key , myObject[key]) // key , value
})
Example 2: going through every attributes of an object javascript
let a = {x: 200, y: 1}
let attributes = Object.keys(a)
console.log(attributes)
//output: ["x", "y"]