-
-
Save keeganbrown/8421527 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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