Can someone explain this piece of code


#1

JavaScript
explain this part:

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

in this

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(254) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve: {
firstName:"Steve",
lastName:"Jobs",
number: "(541) 555-5555",
address: ['TWo Apple Way','Redmond','CA','95014']
}
};

var list = function(friends) {
for (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];
};
};
};

search("Steve");


#2

This part is responsible for searching a friend in your friends list.


#3

thank you much for all your help