for( var i=0; i<contacts.length; i++){
if(contacts[i] === name){
if(contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
} return "No such property";
} return "No such contact";
}
}
and the page gives me as feedback that “No such contact” comes out if inserted a name not existing. I do not understand if it returns it because it’s correct or because I made such a mess that it’s just a coincidence.
You can’t use a loop like that to search through the properties of an object, but you also don’t need to iterate through the properties of the object
You know that there is a firstName property (contacts[i].firstName) and you have an other name of a property that you have to check (contacts[i][prop])