27.loop the loop. undefined array?


#1

https://www.codecademy.com/courses/spencer-sandbox/4/2?curriculum_id=506324b3a7dffd00020bf661#

TypeError: family[i] is undefined


function Person (name, age){
    this.name=name;
    this.age=age;};

family = [];
family.push(new Person("alice", 40));
family.push(new Person("bob", 42));
family.push(new Person("micehlle", 8));
family.push(new Person("timmy", 6));

// loop through our new array
for (var i=0; i <= family.length; i ++) {
    console.log(family[i].name);
    }


#2

so our family has a length of 4, but arrays are zero index based so indexes are:
0, 1, 2 and 3

so we to do i < family.length

and you misspelled michelle


#3

thanks! now it works!


#4