这题怎么解
var contacts=[
{
"firstName":"akira",
"lastName":"Laine",
"number":"0543236543",
"like":["Pizza","Coding","Brownie Points"]
},
{
"firstName":"Harry",
"lastName":"Potter",
"number":"0994372684",
"like":["Pizza","Coding","Brownie Points"]
}
]
function lookUp(firstName,prop){
for(var i=0;i<contacts.length;i++){
if(contacts[i].firstName==firstName){
var j=0;
for(var key in contacts[i]){
if(key==prop){
console.log(contacts[i][prop]);
break;
}
j++;
}
if(j==4){
console.log("No such property");
}
break;
}
}
if(i==contacts.length){
console.log("No such contact");
}
}
lookUp("Harry","like");
lookUp("Bob","number");
lookUp("Harry","math");
for(var i in contacts){
if(contacts[i].firstName == firstName){
contacts[firstName] = contacts[i];
}
}
if(!contacts[firstName]){
return 'No such contact';
}
if(!contacts[firstName][prop]){
return 'No such property';
}
return contacts[firstName][prop];
}
// Only change code below this line
for (var i in contacts)
{if (contacts[i].firstName === firstName && prop in contacts[i])
return contacts[i][prop];}
for ( i in contacts)
{ if (prop in contacts[i] ===false)
return "No such property";
}
for ( i in contacts)
{ if (contacts[i].firstName !== firstName)
return "No such contact";}
// Only change code above this line
}