Skip to content

Instantly share code, notes, and snippets.

@nola
Last active January 3, 2016 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nola/8419770 to your computer and use it in GitHub Desktop.
Save nola/8419770 to your computer and use it in GitHub Desktop.
//create an object
var friends = {};
//add people to it
friends.bill = { //observe this declaration as bill is an object of friends
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
};
//add another
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "(408) 555-5555",
address: ['1 Infinite Loop','Cupertino','CA','95014']
};
//log out all contents of the object
var list = function(obj) {
for(var prop in obj) {
console.log(prop);
}
};
//search for "steve"
var search = function(name) {
for(var prop in friends) {
if(friends[prop].firstName === name) {
console.log(friends[prop]);
return friends[prop];
}
}
};
list(friends);
search("Steve");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment