8. Victory! Search prints twice, why?


So, my code works, and it passes me on to the next lesson. However, my console prints Steve's entry twice, and I'd like to know why. If I remove the return line it only prints once, but that is not correct--according to the the sample format:
return friends[prop];

What is the distinction between these two lines of code and where is my duplicate coming from?

This is my code:

var friends = {
bill: {
firstName: "Bill",
lastName: "Cranston",
number: "714-745-4282",
address: ['500', '21st Street', 'Santa Monica', 'CA', '90404']
steve: {
firstName: "Steve",
lastName: "Thompson",
number: "555-555-5555",
address: ['1000', 'E. 23rd Street', 'Fruitvale', 'CA', '94612']

var list = function(friends) {
for (var key in friends) {

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


And this is what prints:
{ firstName: 'Steve',
lastName: 'Thompson',
number: '555-555-5555',
address: [ '1000', 'E. 23rd Street', 'Fruitvale', 'CA', '94612' ] }
{"firstName":"Steve","lastName":"Thompson","number":"555-555-5555","address":["1000","E. 23rd Street","Fruitvale","CA","94612"]}


You can remove the console.log because return statements are used exclusively for functions.


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