JavaScript Array method: findIndex()
[this page | pdf | back links]
The findIndex() method (when applied to a JavaScript
array) returns
the index of the first element of the array that passes a specified test.
It
has the following syntax with the following parameters. It returns a number
as above (or -1 if no array element passes the test). It only checks values
(i.e. applies the function) up to the first time the test is passed.
array.findIndex(function(currentValue,
index, arr), thisValue)
|
Parameter
|
Required / Optional
|
Description
|
|
function(currentValue,
index, arr)
|
Required
|
A function to be run
for each element
|
|
thisValue
|
Optional
|
A value to be passed to
the function to be used as its ‘this’ value (if empty then thisValue
will be undefined
|
The function
arguments are:
|
Parameter
|
Required / Optional
|
Description
|
|
currentValue
|
Required
|
The value of the
current element
|
|
Index
|
Optional
|
The array index of the
current element
|
|
arr
|
Optional
|
The array object which
the current element belongs to
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Arrays