Array.find
find — Executes a provided function once per array element. If the function returns a true value, it will break the loop and return that value.
Description
Array.find(function callback, [object this])
Parameters
Name | Description | Type | Default | Optional |
---|---|---|---|---|
callback | See callback below. | function | No | |
this | object | Yes |
callback
The following parameters is passed to the callback.
- value
The value of the current index.
- index
The current index.
- array
The array.
Return values
mixed. Returns the value of the found element or undefined if not found.
Changelog
Version | Description |
---|---|
ES 6 | Introduced. |
Examples
Example #1 – find example
Passing in a custom object for this.
Emulates a failed test when the value 2 is discovered. This will make it go to the next iteration.
And if all tests fail.