Standard built-ins
Array.prototype.findIndex()
Visits indices in ascending order until a truthy predicate result. Reads ordinary holes as undefined and supplies value, index and source to the predicate. Matching index, or -1 if none qualifies.
Formal Syntax & Structure
javascript syntaxjavascript
array.findIndex(predicate, thisArg?)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| predicate | function | Tests the current value, index and source. |
| thisArg | any | Optional callback receiver. |
Return Value
number
Matching index, or -1 if none qualifies.
Working Example
Example Snippetjavascript
console.log([1,7,2,9].findIndex(x=>x>5));