Just like with strings and numbers, we can put multiple objects into an array. We want to practice extracting information from different objects which are stored in the same array.
This allows us to put all of our contact objects into a unified list. If the objects are contact entries, then the list is the book binding that ties all of the contact entries together.
- Create an object called
mary
. It has the same properties asbob
. Her name is Mary Johnson, her phoneNumber is"(650) 888 - 8888"
and her email is"mary.johnson@example.com"
. - Create an array called
contacts
. Putbob
in first (at index 0), thenmary
(at index 1). - Write a
console.log
statement that prints out Mary's phone number.
var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};
var mary = {
firstName: "Mary",
lastName: "Johnsons",
phoneNumber: "(650) 888 - 8888",
email: "mary.johnson@example.com"
};
var contacts = [bob, mary];
console.log(contacts[1].phoneNumber);
No comments:
Post a Comment