Answers for "iritating over properties in an array of objects"

6

javascript loop object

let obj = {
  key1: "value1",
  key2: "value2",
  key3: "value3"
}

Object.keys(obj).forEach(key => {
    console.log(key, obj[key]);
});
// key1 value1
// key2 value2
// key3 value3

// using for in - same output as above
for (let key in obj) {
  let value = obj[key];
  console.log(key, value);
}
Posted by: Guest on May-04-2020
4

javascript loop through array of objects

var people=[
  {first_name:"john",last_name:"doe"},
  {first_name:"mary",last_name:"beth"}
];
for (let i = 0; i < people.length; i++) { 
  console.log(people[i].first_name);
}
Posted by: Guest on June-17-2019
-1

iterate over array of object javascript and access the properties

for (let item of items) {
    console.log(item); // Will display contents of the object inside the array
}
Posted by: Guest on April-29-2020

Code answers related to "iritating over properties in an array of objects"

Code answers related to "Javascript"

Browse Popular Code Answers by Language