HELP ME OUT GUYS, Its like No Way Out!


#1

TypeError: Person[40] is not a constructor

// Our Person constructor
function Person(name,age){
this.name = name;
this.age = age;
}
//var family=[];
var family = new Array();
// Now we can make an array of people
family[0] = new Person["alice",40];
family[1] = new Person["bob",42];
family[2] = new Person["michelle",8];
family[3] = new Person["timmy",6];

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

`


#2

the error is how you are instantiating the Person object. The square brackets should be this () instead


#3

Stupid Stupid me !!! Thank you :slight_smile:


#4

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