//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(firstNames, prop){
// Only change code below this line
for (var i=0; i<contacts.length; i++){
if(contacts[i].firstName == firstNames){
for (var j=0; j<contacts[i].length; j++){
if(contacts[i][j] == prop){
return contacts[i][j].prop;
} else {
return "No such property";
}
}
} else{
return "No such contact";
}
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
上面的代码不起作用,特别是在for (var j=0; j<contacts[i].length; j++)
行的行上,因为contacts[i].length
未定义,当我将console.log
语句运行到我的代码中时
您究竟如何定义嵌套在另一个对象中的javascript对象的长度?
答案 0 :(得分:1)
std::vector<std::complex<double> >
原型未定义Object
函数,这就是length
的原因。但是,您可以使用undefined
:
Object.keys