Let's say I have this object:
const people = {
frodo: { name: 'Frodo', age: 33 },
aragorn: { name: 'Aragorn', age: 87 },
legolas: { name: 'Legolas', age: 2931 }
}
And let's say I want to loop over the properties of that object, like this:
for (var person in people) {
console.log(person.name);
}
I get undefined for any property of the person I tried to access. Why does this happen, and what's the correct way to loop the properties of that object and still be able to access their own properties?