var friends = {
bill: {
firstName: 'bill',
lastName: 'Green',
number: ('812381293'),
address : ['chicken st 12','rigth corner']
}
steve: {
firstName: 'steve',
lastName: 'Brown',
number: ('812222381293'),
address : ['chicken st 12','rigth corner']
}
};
var list = function(friends) {
for (var name in friends) {
console.log(name);
}
}
var search = function (friends) {
for (var key in friends) {
if (friends[key].firstName === name) {
console.log(friends[key]);
return friends[key];
}
}
}
我有一個語法錯誤:對象和我的代碼
Unexpected identifier
請告訴我錯我的代碼?
這裏就是我需要在當前的任務做:
Define a function search that takes a single argument, name. If the argument passed to the function matches any of the first names in friends, it should log that friend's contact information to the console and return it.
你錯過之間'}'和'史蒂夫逗號:{' – Koralarts
「定義一個函數搜索**接受單個參數,名稱**「 – Andreas