Answers for "for in key value"

35

javascript foreach get key and 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
})
Posted by: Guest on July-08-2020
1

for in loop key

// if you want to get the 'value' of the key  you can do it this way
const user = {firstName: 'John', lastName: 'Doe'}

for(key in user) console.log(user[key]);
// output : 
// John
// Doe
Posted by: Guest on April-02-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language