Ok, can some help me understand the solution below, from:
javascript-algorithms-and-data-structures/basic-javascript/profile-lookup project
I get that the second line is to control the loop as a counter against how many contacts objects there are.
But, I’m lost as to how we are using x in the third and fourth lines. What is the x doing with contacts?
function lookUpProfile(name, prop) {
for (var x = 0; x < contacts.length; x++){
if (contacts[x].firstName === name) {
if (contacts[x].hasOwnProperty(prop)) {
return contacts[x][prop];
} else {
return “No such property”;
}
}
}
return “No such contact”;
I would greatly appreciate some wisdom as, I can’t seem to figure it out for the life of me…