Search for friend


#1

I keep getting a Syntax Error, but can't seem to find the error location. Thanks for your help!

var friends = {

var friends.bill : {
firstName :"Bill",
lastName : "Smith",
number : "1-858-780-5554",
address : ['214 Oak St','Bic','NY', "12231"]
};

var friends.steve : {
firstName : "Steve",
lastName : "White",
number : "1-114-4456-7777",
address : ['214 Oak St','Bic','NY', "12431"]
};
};

var list = function(object){
for(var key in friends){
console.log(key);
}
};

var search = function(name){
for (var firstName in friends) {
if (friends[firstName].firstName===name){
console.log(friends[firstName]);
return friends[firstName];
}
}
};

search("Bill");
search("Steve");


#2

Ok, here's what a similar program would look like.

var aListOfLists = {}
aListOfLists.theFirstList = {
    'something': 11,
    'another': 12
}
aListOfLists.theSecondList = {
    'A thing': 15,
    'Another': 23
}

also your for/in loop

for (var firstName in friends) {
     if (friends[firstName].firstName===name){
         console.log(friends[firstName]);
         return friends[firstName];
     }
}

is confusing, maybe it should look like this:

for (var someName in friends) {
     if (friends[someName].firstName===name){
         console.log(friends[someName]);
         return friends[someName];
     }
}