27 - Loop the loop


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

var family = new array;
var family[0] = new Person("alice", 40);
var family[1] = new Person("bob", 42);
var family[2] = new Person("michelle", 8);
var family[3] = new Person("timmy", 6);

for (var i = 0; i < family.length; i++) {

Whats wrong with this, it keeps telling me unexpected token [ but i just cant find it!


In the objects array, you don't have to put the "var" before family[x] = new Person...

It should be like this:

family[0] = new Person("alice", 40);


And you need to write new Array with capital A so the program can recognize that you are talking about Array and not some variable called array


That still wouldn't work, dayfiri. Array would need to be a function as well. It should be "new Array();", otherwise there would be an error.


Where you have mentioned "var family=new Array"--> instead use " new Array();"


Can anyone explain to me why I couldn't use a For / In loop to get the same result. My loop was

for (Person in family) {