For the Profile Lookup Problem. Can anyone tell me why I need the brackets instead of dot notation for: return contacts[i][prop];
why doesn’t: return contacts[i].prop work?
// here is my full code to solve the problem…
function lookUpProfile(firstName, prop){
//Only change code below this line
for( var i = 0; i < contacts.length; i++ ){
if( firstName == contacts[i].firstName ) {
if( contacts[i].hasOwnProperty( prop ) ) {
return contacts[i][prop]; //need [] around prop b/c it is an index?
} else {
return “No such property”;
}
}
}
return “No such contact”;