JavaScript Iterator find()
Example
Find the value of the first element with a value over 18:
function myFunc(value) {
return value > 18;
}
const myIterator = Iterator.from([3, 10, 18, 20]);
let result = myIterator.find(myFunc);
Try it Yourself »
Description
The find()
method returns the value of the first element that passes a test.
The find()
method executes a function for each array element.
The find()
method returns undefined
if no elements are found.
The find()
method does not execute the function for empty elements.
The find()
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. Default undefined .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 an ES2025 feature.
ES2025 is fully supported in all modern browsers since May 2025:
Chrome 135 | Edge 135 | Firefox 129 | Safari 18.2 | Opera 120 |
Apr 2025 | Apr 2025 | Aug 2024 | Des 2024 | May 2025 |