# Iterator.find()

> The `.find()` JS method of the `Iterator` object returns the first value of an iterator that passes a test.

## How do I find the first matching value in an iterator?

The method that returns the first yielded value for which the callback returns a truthy value, and stops the iteration. Returns `undefined` if no value is found.

- Topic: Iterator
- Type: method
- Browser support: Chrome 122+, Chrome Android 122+, Edge 122+, Firefox 131+, Firefox Android 131+, Safari 18.4+, Safari iOS 18.4+

## Example

Wrong:

```js
const user = [...users.values()]
  .find((u) => u.email === email);
console.log(user.name);
```

Right:

```js
const user = users.values()
  .find((u) => u.email === email);
console.log(user?.name ?? 'Not found');
```

`find()` searches the iterator directly and stops at the match; optional chaining handles the `undefined` result.

## Common mistakes

- Reusing the iterator after `find()`, which has already closed it.

## Key points

- `find()` is used instead of converting the iterator to an array and calling `find()` on it.
- The code handles `undefined` when no value matches.

## Interview questions

### Is there `findIndex()` for iterators?

No. The callback's second argument is a counter, so you can record it when the test passes.

### What is the difference between `find()` and `filter()` on an iterator?

`find()` returns the first matching value and stops. `filter()` returns a new iterator over all matching values.

## Related cards

- [Iterator.some()](https://wonderium.dev/js/iterator-some.md)
- [Iterator.filter()](https://wonderium.dev/js/iterator-filter.md)
- [Array.find()](https://wonderium.dev/js/array-find.md)
- [Iterator](https://wonderium.dev/js/iterator.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/iterator-find
- Last updated: 2026-11-25
