I'm totally new, so excuse any faux pas. I searched for a solution, but couldn't find anything that answered my question, or at least anything that I could understand.
So here goes: I'd like to iterate through each object in this array and check if firstName ("Akira", in this case) matches up to any of the firstNames within my "contacts" array. At this stage, I'd just like to return the index number of the object(if this is possible). If not, please let me know how I can do this, in the most elementary, 5-year old way possible. Thank you!
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"]
}
function lookUpProfile(firstName, prop){
for (var i = 0; i < contacts.length; i++) {
if (contacts[i][firstName] == firstName){
return i;
}
}
}
lookUpProfile("Akira", "likes");