Loop the loop



It says: TypeError: undefined is not an object (evaluating 'family[i].name'), and also: Oops, try again. It looks like the object at index 0 was not created with the Person constructor

// 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] = Person("alice",40);
family[1] = Person("bob", 42);
family[2] = Person("michelle",8);
family[3] = Person("timmy",6);

// loop through our new array
for (var i=0; i<family.length; i++) {


you can loop through the array using a number equivalent of the items like this,

for (var i = 0; i < 4; i ++) {


Can't see why I should use a defined number, when I'am looping through an array? :slight_smile:
anyways.. Found the error.

I didn't define the Person as a new Object.

So it should be:



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