Exercicio 6 . Liste-os Todos


#1

Não estou a perceber porque não está a dar, alguém consegue ajudar?

var friends =
{
bill: {
firstName: "Bill",
lastName: "Gates",
number:"333888555",
address: [ "abc", "rua 123", "def"]
},
steve: {
firstName:"Steve",
lastName:"Jobs",
number: "444222787",
address: ["hjk", "rua 567", "yui"]
},
}

var list = function(name) {
for (var key in friends) {
if(friends[key].firstName === name){
console.log [key];

}
}
};
list ("Steve");


#2

var friends = new Object ();

friends.bill = {
firstName : "Bill",
lastName : "Gates",
number : "(41) - 9999-8888",
address : ['One Microsoft Way', 'Redmond','Wa','98052']
};

friends.steve = {
firstName : "Steve",
lastName : "Jobs",
number : "(41) 8888-7777",
address : ['One Microsoft Way2', 'Redmond2','Wa','98052']
};

friends.rafael = {
firstName : "Rafael",
lastName : "Fernandes",
number : "(41) 5555-4444",
address : ['Ludovico Kaminski', '2360']
};

var list = function (obj){
for (var bill in obj){
console.log(bill);
}
};

Eu fiz assim e deu certo.