I am trying to loop through an array of objects using a 'for' loop, and want to print the results in a template using Javascript. However, the data in the template comes back as undefined. Not sure where I am going wrong?
const people = [{
name: "Martin",
age: 45
},
{
name: "Steve",
age: 32
}
];
for (let i = 0; i < people.length; i++) {
let template = `
<h2>${people.name}</h2>
<p>${people.age}</p>
`;
document.write(template);
}
people[i].name