6 list 'em


#1


why is it displaying "bill" and "steve" when both are uppercase, and I asked for number?


var friends = {};
   friends.bill = {
       firstName:"Bill",
       lastName:"Gates",
       number:"202-555-0121",
       address:["One Microsoft Way","Redmond","WA","98052"]
       };

   friends.steve = {
       firstName:"Steve",
       lastName:"Jobs",
       number:"202-555-0188",
       address:["1 Infinite Loop","Cupertino","CA","95014"]
       };


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

list();


#2

the objects bill and steve are both lowercase. which is what you are displaying.

You don't ask for the number, number is just a variable you created in the for in loop:

for (var number in friends)

which will list the objects inside your friends object.

if you wanted there number you would need:

console.log(friends[number].number);

you need to access the steve or bill object inside of your friends object, and then get the number from your bill or steve object


#3

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