TypeError: Cannot read property 'firstName' of undefined


#1


var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};
var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};
var contacts = [bob, mary];
function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}
var list=function(){
    var contactsLength=contacts.length;
    for ( var a=0; a<=contactsLength; a++){
        printPerson(contacts[a]);
    }
}
list();


#2

Hi this line

for ( var a=0; a<=contactsLength; a++){

this part

a<=contactsLength

remove the = to <=


#3

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