Standard built-ins
Array.prototype.find()
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 element, or undefined if no match.
Formal Syntax & Structure
javascript syntaxjavascript
array.find(predicate, thisArg?)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| predicate | function | Tests the current value, index and source. |
| thisArg | any | Optional callback receiver. |
Return Value
any
Matching element, or undefined if no match.
Working Example
Example Snippetjavascript
console.log([1,7,2,9].find(x=>x>5));