6. List 'em all - list function prints out names twice


#1

My code is below, the out put prints "bill steve bill steve" with each name on its own line in the console.

var friends = {
bill: {
firstName: "Bill",
lastName: "Bill_last_name",
number: 2348760967,
address: ["1 ■■■■ YOU WAY", "NOWHERE", "RANDOM"]
},
steve: {
firstName: "Steve",
lastName: "Steve_last_name",
number: 4531988716,
address: ["2 ■■■■ YOU WAY", "NOWHERE", "RANDOM"]
}
};

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

list(friends);


#2

Hi,
I pasted your exact code and it prints 'bill steve' only once. Do you still have this problem?


#3

You neeed to delete list(friends) in the last line, then you have both name on time


#4

Instead of list(friends), put list(friends.firstName); this should work


#5

Do you know why you used 'x' as the key?


#6

I don't' could you please explain?