Answers for "javascript foreach object get 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
53

javascript for each key in object

var person={
 	first_name:"johnny",
  	last_name: "johnson",
	phone:"703-3424-1111"
};
for (var property in person) {
  	console.log(property,":",person[property]);
}
Posted by: Guest on July-22-2019
1

javascript foreach array of object get value by key

const object1 = {
  a: 'somestring',
  b: 42
};

for (const [key, value] of Object.entries(object1)) {
  console.log(`${key}: ${value}`);
}
Posted by: Guest on June-18-2021

Code answers related to "javascript foreach object get key value"

Code answers related to "Javascript"

Browse Popular Code Answers by Language