So I have these two for loops. In the first loop the message says exactly what I want it to say; Hello Herbert, Hello Peter.
But in the second one it says; Hello undefined.
What is the difference between these two blocks of code, and why does the second one returns undefined?
let people = [
{
name: "Herbert",
occupation: "Vildstaed",
language: ["Finnish", "English", "German"]
},
{
name: "Peter",
occupation: "Skalnstead",
language: ["German", "Livonian Dialect"]
}
];
for(var i = 0; i < people.length; i++){
alert("Hello " + people[i].name)
}
for(let person in people) {
alert("Hello " + person.name)
}