Initial data:
There is an array of contacts, each element is an object with its own properties. We need to make a function that takes the value of first and compares it with all the firstName array. If there is a match, then you need to output the second specified value.
In the specific case, this is the lastName value of the same object. I already and so, and tried, nothing comes out.
It seems that return contacts[i][prop]; just not working.
As a result, should output: "Vos"
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(first, prop) { for (var i = 0; i < contacts.length; i++) { if (contacts[i].firstName == first) { document.write('First name has matches<BR>') if (contacts[i].hasOwnProperty(prop)) { document.write('Prop exist<BR>'); return contacts[i][prop]; } return "No such property"; break; } } return "No such contact"; } lookUpProfile("Kristian", "lastName"); document.write(lookUpProfile());