My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Why it returned like this contacts[x][prop] ?

Sohail Badghisi's photo
Sohail Badghisi
·Sep 16, 2019
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
];




function lookUpProfile(name, prop) {
for (var x = 0; x < contacts.length; x++) {
    if (name === contacts[x].firstName) {
        if (contacts[x].hasOwnProperty(prop)) {
            return contacts[x][prop];
        } else {
            return "No such property";
        }
    }
}
return "No such contact";
}
// Change these values to test your function
console.log(lookUpProfile("Akira", "likes"));
****

I know all other codes, but why it returned the prop var and x like a two dimensional array?