This seems like a very simple question so I hope there's a simple solution!
If I have an array of objects:
let objArray = [
{id: 2, name: Bob},
{id: 4, name: James},
{id: 3, name: Sally},
{id: 9, name: Jenny}
]
If I then have another variable that tells me which object in the array I want, how would I go about using it?
let requiredObj = 2
I want to use this variable to return the name 'Bob'. So far I've been doing it by running a for loop and checking each of the ids against the requiredObj. This doesn't seem like the best way to do it, so was hoping there's a 'right way' that I'm not aware of?