27. Loop The Loop error message. Help Please?



here is my code:

// Our Person constructor
function Person(name, age) {
this.name = name;
this.age = age;
// Now we can make an array of people
var family = new Array();
family[0] = new Person ("alice", 40);
family[1] = new Person ("bob", 42);
family[2] = new Person ("michelle", 8);
family[3] = new Person ("timmy", 6);
// loop through our new array
for (var i = 0; i <= family.length; i++) {
console.log (family[i].name);

I am getting an error message with red triangle:

Oops, try again. It looks like you have an error in your code. Here's the message: TypeError: Cannot read property 'name' of undefined

then I get this error in the console window:

We're running a test below to make sure your code works.
TypeError: Cannot read property 'name' of undefined

I'm sure this is something simple, I'm just not seeing it. Thank you for any and all help!

Replace this line with your code.

indent preformatted text by 4 spaces


When i reaches family.length it is out of range.

 i < family.length;


Thank you, that worked. I appreciate the help.


A post was split to a new topic: (family[i].name)" is not defined