Skip to content

Instantly share code, notes, and snippets.

@anuoluwapo
Last active August 7, 2016 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anuoluwapo/5848ed628f8bd827ec5da4aec3fc6d4b to your computer and use it in GitHub Desktop.
Save anuoluwapo/5848ed628f8bd827ec5da4aec3fc6d4b to your computer and use it in GitHub Desktop.
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];
var list = function(){
for (var i = 0; i < contacts.length; i++) {
console.log(contacts[i]);
}
}
function search(lastName){
for(var i = 0; i < contacts.length; i++){
if(contacts[i].lastName === lastName){
console.log("Bob Jones");
}
}
}
function add(firstname, lastname, phonenumber, eMail){
newEntry = {
firstName: firstname,
lastName: lastname,
phoneNumber: phonenumber,
email: eMail
};
contacts.push(newEntry);
}
console.log(add("Anu", "Oluwapo", "12355555", "alaja@eko.cc"));
console.log(list());
//give this output
>Object { firstName: "Bob", lastName: "Jones", phoneNumber: "(650) 777-7777", email: "bob.jones@example.com" }
>Object { firstName: "Mary", lastName: "Johnson", phoneNumber: "(650) 888-8888", email: "mary.johnson@example.com" }
>undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment