What does this error message mean!



when I run my code I'm not entirely sure what happens, but it prints out the four names and an error message that says TypeError: Cannot read property 'name' of undefined

var Person = function(name, age)
    this.age = age;
    this.name = name;

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);

for(i = 0; i <= family.length; i++)
    console.log(family[i].name + " ");


speciically, it prints this to the console:


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


There is the reason, There is no family[4].


thanks (i feel like an idiot)


Don't. It's a common error, and one you will likely not make again. So be good to yourself.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.