I don't understand the function we used, help?


This is the part of the code I dont understand:

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

I dont get 3 things, or I am at least not sure how to get them right.

1-the name in the function(name), doesnt actually do anything? it is just for us to remember what this function does?
2-the key here is just any input that we choose to put in? so doesnt actually matter what we write instead of key?
3-In this part : if(friends[key].firstName === name), i dont get what friends[key].firstName is. Is it something along the lines of "look for the first name of ALL the friends?"?


  1. name has a use, which is comparison, otherwise it wouldn't be there.

  2. Key is a name for the component in the array, you can name it what you want.

  3. It is, then it compares it to name.