const animals = ['hippo', 'tiger', 'lion', 'seal', 'cheetah', 'monkey', 'salamander', 'elephant']; const foundAnimal = animals.findIndex(a => { return a === 'elephant'; }); console.log(animals[foundAnimal]); // uses function's returned index to display value const startsWithS = animals.findIndex(letter => { return letter[0] === 's'; }); console.log(startsWithS); // function returns index number of first TRUE element console.log(animals[startsWithS]); // used to display that element's value
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter