Skip to content

Instantly share code, notes, and snippets.

@Philocoder93
Created December 22, 2016 00:20
Show Gist options
  • Select an option

  • Save Philocoder93/cbbf2fdd91167e9afe3477b07adfca52 to your computer and use it in GitHub Desktop.

Select an option

Save Philocoder93/cbbf2fdd91167e9afe3477b07adfca52 to your computer and use it in GitHub Desktop.
var john = {
'firstName':'john',
'lastName':'doe',
'phone':'(512) 355-0453',
'email':'johndoe@email'
};
var jane = {
'firstName':'jane',
'lastName':'doe',
'phone':'(312) 641-2203',
'email':'janedoe@email.com'
};
var suzie = {
'firstName':'suzie',
'lastName':'smith',
'phone':'(415) 604-4219',
'email':'suziesmith@email.com'
};
var contacts = [];
contacts[0] = john;
contacts[1] = jane;
contacts[2] = suzie;
var addContact = function(newContact) {
contacts.push(newContact);
return(contacts);
};
var listContacts = function() {
for (i=0;i<contacts.length;i++) {
console.log(contacts[i]['firstName']);
console.log(contacts[i]['lastName']);
}
};
var search = function(name) {
for (i=0;i<contacts.length;i++) {
if (contacts[i]['firstName'] = name) {
return contacts[i];
}
else if (contacts[i]['lastName'] = name) {
return contacts[i];
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment