Here is the code:
// The Person constructor
function Person(name, age) {
this.name = name;
this.age = age;
}
// Now we can make an array of peoples
var family = new Array();
family[0] = Person("alice", 40);
family[1] = Person("bob", 42);
family[2] = Person("michelle", 8);
family[3] = Person("timmy", 6);
// loop through our new array
for ( i=0; i < family.length; i++; ) {
console.log(family[i].name)
};
The expected output of this script is:
alice
bob
michelle
timmy
But the output is:
Uncaught TypeError: Cannot read property 'name' of undefined (anonymous function)