List 'em All - Repeats my list twice, why?


#1
var friends = {};
friends.bill = {
    firstName: "Bill",
    lastName: "Gates",
    number: "561-555-5555",
    address: ["some","friggin","mansion"]
};
friends.steve = {
    firstName: "Steve",
    lastName: "Jobs",
    number: "561-666-6666",
    address: ["Burning", "in", "hell"]
};
friends.saad = {
    firstName: "Carl",
    lastName: "John",
    number: "561-555-8758",
    address: ["3686", "Moon", "South", "Florida", "33244"]
};

var list = function(object) {
    for (var property in object) {
        console.log(property);
    }
}

list(friends);

The code works but it spits out the names TWICE. I.e.
bill
steve
carl
bill
steve
carl

Can anyone see why my code logs my names twice? Thank you.


#2

Hi remove that

list(friends);

#3

So now, it spits it out once plus the information of Carl. Why?

I assumed it wouldn't log anything since I didn't command it to log anything ( list(friends); )

Why does it log list when it hasn't even been commanded to do so?


#4

Hi,

I write this:

var friends = {};

friends.bill = {
firstName: "Bill",
lastName: "Smith",
number : "(09) 9999999",
address: ["1 Neil Ave", "Te Atatu", "Auckland"]

};

friends.steve = {
firstName:"Steve",
lastName: "Wilson",
number: "(09) 5555555",
address: ["15 Roby Street", "Te Atatu", "Auckland"]
};

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

and in the display, I get this:

bill
steve
{"firstName":"Steve","lastName":"Wilson","number":"(09) 5555555","address":["15 Roby Street","Te Atatu","Auckland"]}

Is this expected? It's spitting out all the things I've stored about Steve.