Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var bob = {
- firstName: "Bob",
- lastName: "Jones",
- phoneNumber: "(650) 777 - 7777",
- email: "bob.jones@example.com"
- };
- var mary = {
- firstName: "Mary",
- lastName: "Johnson",
- phoneNumber: "(650) 888 - 8888",
- email: "mary.johnson@example.com"
- };
- var contacts = [bob, mary];
- function printPerson (person) {
- console.log(person.firstName + " " + person.lastName);
- }
- function list (){
- numberOfItems = contacts.length;
- for (i=0; i<numberOfItems; i++){
- printPerson(contacts[i]);
- }
- }
- function search(lastName){
- numberOfContacts = contacts.length;
- for (i=0; i<numberOfContacts; i++){
- if(lastName === contacts[i].lastName)
- return printPerson(contacts[i]);
- }
- }
- search("Johnson");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement