Tell us what’s happening:
Hi Friends,
I have a big question :-). Can please someone explain me the double if ? Until now I know just the single if.
Ps: I’m a beginner
Thank so much in advance.
if (contacts[x].firstName === name) {
**if (contacts[x].hasOwnProperty(prop)) {**
return contacts[x][prop];
} else {
return "No such property";
}
}
}
Your code so far
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["JavaScript", "Gaming", "Foxes"]
}
];