Answers for "for each item in object javascript"

10

foreach object javascript

const students = {
  adam: {age: 20},
  kevin: {age: 22},
};

Object.entries(students).forEach(student => {
  // key: student[0]
  // value: student[1]
  console.log(`Student: ${student[0]} is ${student[1].age} years old`);
});
/* Output:
Student: adam is 20 years old
Student: kevin is 22 years old
*/
Posted by: Guest on September-30-2020

Code answers related to "for each item in object javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language