In a prior optional project or exercise in this course, we had to use the
.indexOf() method, which returns the index of a given element.
In this one we are taught
.findIndex(), which does the same thing, but with a callback function as a parameter, which makes it more roundabout to achieve, seemingly, the same thing.
Is there any good example for when
.findIndex() is preferable over
const animals = ['hippo', 'tiger', 'lion', 'seal', 'cheetah', 'monkey', 'salamander', 'elephant'];
const foundAnimal = animals.findIndex(animal => animal === 'elephant'); //returns 7
const findAnimal = animals.indexOf('elephant'); //also returns 7