Array.find
Array.find
Function
Returns the first element for which the callback result is true.
Syntax
array.find(callback)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| callback | Fn | No | Empty | The callback signature is fn(value, index, current). |
Return value
| Type | Description |
|---|---|
| Any/Empty | Returns the element if found; returns Empty if not found. |
Example
items = [1, 2, 3] result = items.find(fn(value) { value > 1 }) // Output: 2 print result
Notes
- Search from left to right.