Searching Arrays with indexOf and lastIndexOf

In JavaScript, the indexOf() method returns the first index at which a specified element can be found in an array. If it does not exist in the array, -1 is returned instead. Similarly, lastIndexOf() returns the last index where an element appears or -1 if it doesn't exist within the array. These methods are incredibly useful when searching for elements and are commonly used in various coding instances.

Try it