Codecademy - JS contact list
注意object friends和object bill, object steve之间的从属关系,还有最后一个for loop。
var friends = new Object();
friends.bill = {
name: "bill",
firstName: "Bill",
lastName: "Kevin",
number:001,
address:["Bedok", "Singapore"]
};
friends.steve = {
name: "steve",
firstName:"Steve",
lastName: "Kevin",
number: 002,
address: ["Tampines", "Singapore"]
}
var list = function (friendList) {
for(var friend in friendList){
//console.log(friend);
}
};
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");