JavaScript Iterator find() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Instance method

Definition

iterator.find(callback) walks each value until your function says "yes, this one". Then it returns that value. If no value passes the test, the result is undefined.

The method consumes the iterator. When a match is found, remaining values are not read, and the iterator is closed. You cannot continue from the same iterator afterward.

Remember
iterator.find(callback)

first match     → that value
no match        → undefined
stops early     → yes, on the first match

Consumes the iterator (it is closed after the call).
Callback gets (value, index).

Syntax

Call it on an iterator and pass a function that returns true for the value you want.

JavaScript
const nums = [1, 2, 3, 4, 5].values();

const firstBig = nums.find((n) => n > 3);
console.log(firstBig);   // 4
CallWhat it does
iterator.find(callback)Return the first value that passes the test, or undefined.
[1, 2, 3].values().find(fn)Get an iterator from an array, then find the first match.
callback(value, index)Your function receives the current value and its zero-based index.

A standard JavaScript method (Iterator helpers, Baseline 2025) on every iterator, from Iterator.prototype. No import required. Siblings: Iterator.concat(), Iterator.from(), Iterator.zip(), Iterator.zipKeyed(), chunks(), drop(), every(), filter(), flatMap(), forEach(), includes(), join(), map(), reduce(), some(), take(), toArray(), windows(), [Symbol.dispose](), [Symbol.iterator]().

Library declarations
JavaScript
// Iterator helpers (Baseline 2025)
Iterator.prototype.find(callbackFn)

// callbackFn : (value, index) => boolean-like
// returns    : the matching value, or undefined

Parameters

ParameterDescription
callbackFnRequired. A function called for each value until a match is found. Return a truthy value to select that item, or a falsy value to keep looking. It receives value and index (starting at 0).

Return Value

Return ValueDescription
value or undefinedThe first value for which the callback returned a truthy result. If nothing matched (or the iterator was empty), the result is undefined. The iterator is closed either way.

JavaScript Examples

Example 1 — Find the First Matching Value

Get the first number greater than 3 from an iterator.

JavaScript
const nums = [1, 2, 3, 4, 5].values();
const firstBig = nums.find((n) => n > 3);

console.log("First > 3: " + firstBig);
Try It Yourself

The Try It page first checks that iterator.find() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.

How It Works

  1. Make an iterator. [1, 2, 3, 4, 5].values() yields each number in order.
  2. Test each value. 1, 2, and 3 fail the test n > 3.
  3. Return the match. 4 passes, so find() returns 4 and stops. 5 is never read.

Example 2 — See What Happens When Nothing Matches

Search for a value that is not there, and get undefined.

JavaScript
const nums = [1, 2, 3, 4, 5].values();
const huge = nums.find((n) => n > 100);

console.log("Found: " + huge);
console.log("Type: " + typeof huge);
Try It Yourself

The Try It page first checks that iterator.find() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.

How It Works

  1. Search the whole iterator. Every number is 5 or less, so none pass n > 100.
  2. No match. When the iterator ends without a hit, find() returns undefined.
  3. Check the type. typeof huge is "undefined", which is the usual "not found" result.

Example 3 — Use Value and Index Together

Find the first value that equals ten times its index (starting at 1 for display).

JavaScript
const nums = [10, 20, 30, 40].values();
const match = nums.find((n, i) => n === (i + 1) * 10);

console.log("Match: " + match);
Try It Yourself

The Try It page first checks that iterator.find() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.

How It Works

  1. Callback gets two args. n is the value and i is the zero-based index.
  2. First value wins. At index 0, 10 === 1 * 10 is true, so 10 is returned.
  3. Later values skipped. 20, 30, and 40 are never tested once a match is found.

Browser & Runtime Support

Iterator.prototype.find() is an Iterator helper (Baseline Newly available since March 2025). It works in current browsers and in Node.js 22 or newer.

✓ Baseline 2025 · Newly available

iterator.find()

Supported in Chrome 122+, Edge 122+, Firefox 131+, Safari 18.4+, Opera 108+ and Node.js 22+. Internet Explorer never got it.

2025 Standard since
Google Chrome 122+ · Desktop & Mobile
Full support
Microsoft Edge 122+ · Chromium based
Full support
Mozilla Firefox 131+ · Desktop & Mobile
Full support
Apple Safari 18.4+ · macOS & iOS
Full support
Opera 108+ · Chromium based
Full support
Samsung Internet 26+ · Android
Supported
Android WebView 122+ · Chromium based
Supported
Node.js 22+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
iterator.find() Current browsers

Bottom line: Check support with a typeof test before you use it in older browsers. Prefer chaining helpers and calling toArray() last.

Frequently Asked Questions

It returns the first value from an iterator that passes your test function. If nothing matches, it returns undefined. The iterator is consumed.
It returns the value. The index is only passed into your callback as the second argument if you need it while testing.
find() returns undefined. That is different from find() never finishing on an infinite iterator when the callback never returns a truthy value.
No. find() closes the iterator, even when it stops early on a match. Call .values() again (or make a new iterator) if you need another pass.
The idea matches Array.prototype.find(), but it works on an iterator. Feature-detect Iterator helpers in older browsers before you rely on them.

Next: flatMap()

Learn how to map each value to zero or more results and flatten them into one iterator.

flatMap() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful