This code is about to access the property of an object If the firstname of an objet is same
Objets in an Array
const contacts = [{
"firstName": "Akira",
lastName: "Laine",
number: "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"],
}
];
function lookUpProfile(Names, prop) {
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstname === Names) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
}
}
return "No such contact";
}
let myData = lookUpProfile("Akira", "likes");
console.log(myData);
The First one is my code, can someone tell me what's wrong with my code. And what's wrong with the logic