Search for a friend


#1


I don't know what is wrong about this.


var friends = {
    bill: {
        firstName:"Bill",
        lastName:"Gates",
        number:"09756684136",
        address:['Alabang','Muntinlupa','City']
        },
    steve: {
        firstName:"steve",
        lastName:"Jobs",
        number:"09757173165",
        address:['GMA','Cavite']
        }
}
 var list = function (friends)
 {
     for(var key in friends)
     {
         console.log(key);
     }
 }
 var  search = function(name)
 {
     for(var key in friends)
     {
         if(friends[key].firstName === name)
         {
             console.log(friends[key]);
             return friends[key];
         }
         else
         {
             console.log("Invalid!");
         }
     }
 }


#2

here:

firstName:"steve",

Steve is not written with uppercase first letter, so when you then search for Steve, its not found (string comparison is case sensitive)


#3

Thanks a lot. it really helps me


#4

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