Loop the loop


i got stuck , but i could find the mistake

function Person(name,age){
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(“name is”+family[i].name)}


using <= in the for loop means the loop will also try to access 5th item (at index 4) of the array, which doesn’t exist, which is what throws the error


thank you for your help


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