Why does my code return the entire structure of Steve twice and Bill once?


#1

var friends = {
bill:{firstName:"Bill", lastName:"Peters", number:"9283588551",address: ["30180 N Desert Willow blvd", "San Tan Valley", "AZ", "85143",],},
steve:{firstName:"Steve", lastName:"Krumwied", number:"6022454583",address: ["30180 N Desert Willow blvd", "San Tan Valley", "AZ", "85143",],},
};

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

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

search("steve");

Why does my code return an entire information list of Steve twice and Bill once? Is there a way to fix this? Also what is the purpose of the firstName in the [] after friends?


#2

@webrunner86761,

+++ contact list explained
object description
search as function
for-in loop explained
http://www.codecademy.com/forum_questions/54a616f9937676fb3d0024c7

=============================================

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

in your case

search("Steve");
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

Please help; Bill Gates is taking over my search function!
#3

Just wanted to tack on a link to @jibblyj and @leonhard.wettengmx.n's comments here regarding your first question as I think it might be relevant and if so, Chris and Leon have elaborated in more detail the second part of his answer there.