JavaScript Iterator map() Method

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

Definition

iterator.map(callbackFn) walks the source iterator and calls callbackFn on each value. It returns a new lazy iterator that yields the callback results one by one — nothing is stored in an array until you pull values.

Because the result is still an iterator helper, you can chain other helpers such as filter() or take(), then finish with toArray() or a for...of loop when you need the values.

Remember
iterator.map(callbackFn)

each value     → callback runs once
returns        → a new lazy iterator (not an array)
pull values    → toArray() or for...of

Start from .values() or a generator
Chain helpers, collect at the end

Syntax

Call map() on an iterator and pass a function that turns each value into a new one.

JavaScript
const it = [1, 2, 3].values();

const doubled = it.map((n) => n * 2);

console.log(doubled.toArray());   // [2, 4, 6]
CallWhat it does
iterator.map(callbackFn)Return a lazy iterator of callbackFn(value) for each source value.
iterator.map(fn).toArray()Map values, then collect them into an array.
[1, 2, 3].values().map(fn)Start from an array iterator with .values().
iterator.map(fn).filter(pred)Chain helpers; work stays lazy until you consume.

An Iterator helper (Baseline Newly available) on Iterator.prototype. No import required. Feature-detect before use in older engines. Siblings: Iterator.concat(), Iterator.from(), Iterator.zip(), Iterator.zipKeyed(), chunks(), drop(), every(), filter(), find(), flatMap(), forEach(), includes(), join(), reduce(), some(), take(), toArray(), windows(), [Symbol.dispose](), [Symbol.iterator]().

Library declarations
JavaScript
// Iterator helpers (Baseline Newly available)
Iterator.prototype.map(callbackFn)

// callbackFn(value) : returns the mapped value
// returns          : a new lazy iterator helper

Parameters

ParameterDescription
callbackFnRequired. Called once per value as callbackFn(value). Its return value is what the new iterator yields.

Return Value

Return ValueDescription
Iterator helperA new lazy iterator that yields mapped values. The source is not turned into an array automatically — use toArray() or loop with for...of when you need results.

JavaScript Examples

Example 1 — Map Values from an Array Iterator

Start with [1, 2, 3].values(), double each number, and collect the result with toArray().

JavaScript
const nums = [1, 2, 3].values();
const doubled = nums.map((n) => n * 2);

console.log(doubled.toArray());
Try It Yourself

The Try It page first checks that iterator.map() 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. Get an iterator. [1, 2, 3].values() yields 1, then 2, then 3.
  2. Map each value. The callback multiplies by 2, so the helper will yield 2, 4, 6.
  3. Collect results. toArray() pulls every remaining value into a normal array for printing.

Example 2 — Chain map() with filter()

Map first, then keep only the large results. Helpers stay lazy until toArray().

JavaScript
const result = [1, 2, 3, 4, 5].values()
  .map((n) => n * 10)
  .filter((n) => n > 20)
  .toArray();

console.log(result);
Try It Yourself

The Try It page first checks that iterator.map() 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. Map to tens. Each number becomes 10, 20, 30, 40, 50.
  2. Filter the large ones. Only values greater than 20 pass through.
  3. Finish with an array. toArray() gives [30, 40, 50].

Example 3 — Map Values from a Generator

Build values with a small generator function, map them to strings, and print with for...of.

JavaScript
function* letters() {
  yield "a";
  yield "b";
  yield "c";
}

const upper = letters().map((ch) => ch.toUpperCase());

for (const ch of upper) {
  console.log(ch);
}
Try It Yourself

The Try It page first checks that iterator.map() 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. Yield three letters. The generator produces "a", "b", and "c".
  2. Map to uppercase. Each character becomes "A", "B", "C".
  3. Loop to print. for...of pulls values one at a time without building an array first.

Browser & Runtime Support

Iterator.prototype.map() 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.map()

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.map() 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 a lazy iterator that yields callbackFn(value) for each value from the source iterator. You usually finish with toArray() or for...of to see the results.
No. It returns another iterator helper. Call toArray() (or loop with for...of) when you want a normal array or printed values.
Only when someone pulls the next value from the mapped iterator. If you never consume it, the callback never runs.
Use array.values(), a generator, Iterator.from(...), or any object that already is an iterator with helpers.
Yes. Chain filter(), take(), drop(), and similar helpers, then collect once at the end with toArray() or a loop.

Next: reduce()

Learn how to fold every value from an iterator into a single result with reduce().

reduce() 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.

14 people found this page helpful