我似乎無法從多維數組中獲取記錄。這並沒有給我任何特別的錯誤,可以讓我明確自己在做錯什麼。javascript while while獲取記錄信息的循環
你能協助嗎?
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
function lookUpProfile(firstName, prop){
// Only change code below this line
var i = 0;
while(i < contacts.length) {
if (contacts[i].firstName === firstName) {
return contacts[i].prop;
}
i++;
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
contacts [i] [prop];您使用點符號錯誤 – mplungjan
http://underscorejs.org/#findWhere – Kalman
問題如此微不足道,爲什麼還要使用下劃線? – mplungjan