Finds the index of a given element in an array.
The array in which to find the element.
The element to find.
The index of the element in the array, or -1 if the element is not found.
const arr = [1, 2, 3, 4, 5];const element = 3;const index = findIndex(arr, element);console.log(index); // 2 Copy
const arr = [1, 2, 3, 4, 5];const element = 3;const index = findIndex(arr, element);console.log(index); // 2
Finds the index of a given element in an array.