How I would print lastName or address?


#1

@mtf care to explain how I would print lastName or address? Would I need to create another function?


Contact List: 6. List them all
#2

object = {
    member_variable: {
        member_key: value
    }
};

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way','Redmond','WA','98052']
    }
};
console.log(friends.bill.lastName);    # Gates

The list function shows us how to access the member variables of the main object. Those variables point to objects, also, whose member variables are assigned name, number and address properties.

Iterating over the objects is done in the same way, with an inner loop.

for (var member in friends) {                  // member will be 'bill'
    for (var key in member) {                  // key will be 'firstName', etc.
        console.log(key + " " + member[key];   // member[key] will be 'Bill', etc.
    }
}

#3

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