Introduction
Have you ever been on a treasure hunt? The JavaScript world is not much different when it comes to finding elements in an array. Two methods — indexOf and findIndex — serve as your treasure maps. But like all maps, these two have their own unique characteristics. Understanding the nuances between indexOf and findIndex can save you a lot of time and confusion.

So, buckle up as we delve deep into the journey of these two JavaScript methods and explore their similarities, differences, and use-cases.
What Are indexOf and findIndex?
Before diving into the differences, let's understand what these two methods are designed to do.
indexOf
The indexOf method is used to find the index of a specific element in an array. It performs a strict equality (===) check and returns the index of the first match it encounters.
Output:

findIndex
The findIndex method, on the other hand, is a bit more flexible. It allows you to find the index of an element based on a condition. You pass a callback function that returns a boolean value to signify a match.
Output:

The Key Differences
While both methods help you find the index of an element, the way they do it and what they offer are different.
Type of Comparison
indexOf: Uses strict equality (===) for comparison.
findIndex: Allows custom comparison through a callback function.
Flexibility
indexOf: Limited to direct value comparisons.
findIndex: Highly flexible, allowing complex conditions.
Return Value
Both methods return -1 if the element is not found. However, findIndex can return -1 even if an element exists but doesn't meet the condition specified in the callback.
Performance
indexOf: Generally faster for simple lookups due to the absence of a callback function.
findIndex: May be slower for large arrays as it executes the callback for each element until a match is found.