Here is the code
var contacts = { //object
"Father": {
"Name": "X",
"Age": "48",
"phoneNumber": "99373xxxxx",
"Likes": ["Cricket", "spicyFood"]
},
"Mother": {
"Name": "Y",
"Age": "39",
"phoneNumber": "79788xxxxx",
"Likes": ["comedyShows", "spicyFood"]
},
"Sister": {
"Name": "Z",
"Age": "8",
"phoneNumber": "Not Available",
"Likes": ["funnyVideos", "Sweets"]
}
};
function lookUp(name, prop) {
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].Name === name) {
return contacts[i][prop] || "No such property";
};
}
return "No such value";
}
var data = lookUp("Z", "Likes");
console.log(data);
Whenever I compile the code, it returns "No such value", as if neglecting the for loop that was inserted. How to fix this?