The very first thing I notice is that your if condition will never run, because the name parameter will not equal the string āfirstNameā. Were you trying to access the objectās firstName property?
I was assuming it was because i was accessing it like that but what confuses me is that if I do use a zero based index like contact[0], wouldnāt it only check the first object within the array? For it to check the whole collection would it be like contact[0-3]? Which is probably incorrect
Youāve got your loop index i, which corresponds to the indexes of the contacts array (because you initialize i to 0, and the terminal condition is i < contacts.length). You could access each contact in the array in turn by utilizing that i variable within the loop.
If you notice then you can see that ācontactsā is an array.
Arrays can only be accessed using numbers. For example: contacts[0] or contacts[1] etc.
You have tried to access the array by doing contacts[name].
This you can do if contacts is an object. But it is not. ānameā is a variable. Hence your fucntion will not run.