I have the following array of objects:
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"]
}
];
I want to define a function lookUpProfile(firstName, prop)
that is for input:
lookUpProfile("Akira", "likes");
will return:
["Pizza", "Coding", "Brownie Points"]
This is my solution so far, which still does not return:
function lookUpProfile(firstName, prop){
for(var i = 0; i < contacts.length; i++){
if(contacts[i].firstName == firstName){
for(var j = 0; j < contacts[i].length; j++){
if(contacts[i].hasOwnProperty(prop))
return prop;
}
}
}
}
Anyone have an idea to solve this? Thanks