JavaScript Iterator find()
Example
Find the value of the first element with a value over 18:
// Create Iterator
const myIterator = Iterator.from([3, 10, 18, 20]);
// Find first element greater than 18
let result = myIterator.find(x => x > 18);
Try it Yourself »const myIterator = Iterator.from([3, 10, 18, 20]);
// Find first element greater than 18
let result = myIterator.find(x => x > 18);
Description
Thefind() method returns the value of the first element that passes a test.
Thefind() method executes a function for each array element.
Thefind() method returnsundefined if no elements are found.
Thefind() method does not execute the function for empty elements.
Thefind() method does not change the original iterator.
Syntax
iterator.find(function(currentValue, index, arr),thisValue)
Parameters
| function() | Required. A function to run for each iterator element. |
| currentValue | Required. The value of the current element. |
| index | Optional. The index of the current element. |
| arr | Optional. The array of the current element. |
| thisValue | Optional. Defaultundefined.A value passed to the function as its this value. |
Return Value
| Type | Description |
| A value | The value of the first element that pass the test. Otherwise it returns undefined. |
Browser Support
iterator.find() is a JavaScript 2025 feature.
ES 2025 is supported in all modern browsers sinceMay 2025:
| Chrome 136 | Edge 136 | Firefox 129 | Safari 18.2 | Opera 120 |
| Apr 2025 | Apr 2025 | Aug 2024 | Des 2024 | May 2025 |

