JavaScript Array findIndex()
JavaScript Array findIndex()
The findIndex() method is used to execute a function for each array element. It returns the index of the first element that passes a test. It returns -1 if no match is found. It does not execute the function for empty array elements and does not change the original array.
Syntax:-
Its syntax is:- array.findIndex(function(currentValue, index, arr), thisValue)
Return:-
Its return is:- an index number of first element that passed test else -1.
Further Explanation:-
Parameter | Description |
function() | Required. A function to run for each array element. |
currentValue | Required. The value of the current element. |
index | Optional. The index of the current element. |
arr | Optional. The array of the current element. |
thisValue | Optional. A value is passed to the function as this value. Default is undefined. |