Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
1,389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. var contacts = [
  2. //John Doe's profile
  3. { 'firstName' : 'John',
  4. 'lastName' : 'Doe',
  5. 'phone' : '(512) 355-0453',
  6. 'email' : 'johndoe@email.com'
  7. } ,
  8. //Jane Doe's profile
  9. { 'firstName' : 'Jane',
  10. 'lastName' : 'Doe',
  11. 'phone' : '(312) 641-2203',
  12. 'email' : 'janedoe@email.com'
  13. } ,
  14. //Suzie Smith profile
  15. { 'firstName' : 'Suzie',
  16. 'lastName' : 'Smith',
  17. 'phone' : '(415) 604-4219',
  18. 'email' : 'suziesmith@email.com'
  19. } ,
  20. ];
  21.  
  22. console.log(contacts);
  23.  
  24. var addContact= function(newContact) {
  25. contacts.push(newContact);
  26. } ;
  27.  
  28.  
  29.  
  30. console.log(contacts);
  31.  
  32. var listContacts = function() {
  33. for ( var i = 0 ; i < contacts.length ; i++){
  34. console.log(contacts[i].firstName + ' ' + contacts[i].lastName);
  35. }
  36. };
  37.  
  38. listContacts();
  39.  
  40. var search = function(name) {
  41. for (var a = 0; a < contacts.length ; a++){
  42. if (contacts[a].firstName + ' ' + contacts[a].lastName === name)
  43. {
  44. console.log("Phone: " + contacts[a].phone);
  45. console.log("email: " + contacts[a].email);
  46. }
  47. }};
  48.  
  49.  
  50. search("John Doe");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement