JavaScript Iterator Iterator.from() Method

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

Definition

Iterator.from(object) returns a proper Iterator. If you pass an iterable (such as an array), it calls [Symbol.iterator]() and wraps that. If you pass a plain iterator, it wraps that too.

The point is simple: after from(), you can use Iterator helpers such as map(), filter(), take(), and toArray() on the result.

Remember
Iterator.from(object)

iterable  → uses [Symbol.iterator]()
iterator  → wraps next()

result is a proper Iterator
then you can chain .map / .filter / .toArray

already an Iterator? returned as-is

Syntax

Pass an iterable or an iterator. Then chain helpers or read values with next().

JavaScript
const it = Iterator.from([10, 20, 30]);

console.log(it.next().value);              // 10
console.log(it.toArray().join(", "));      // 20, 30
CallWhat it does
Iterator.from([1, 2, 3])Make an Iterator from an array.
Iterator.from(array.values())Wrap an array iterator so helpers are available.
Iterator.from(obj).map(fn).toArray()Convert, transform, then collect into an array.
Array.from(iterable)Build an array right away. Different goal than Iterator.from().

A standard JavaScript static Iterator helper (Baseline Newly available). Call it as Iterator.from(...). Works in current browsers and in Node.js 22 or newer. Siblings: Iterator.concat(), Iterator.zip(), Iterator.zipKeyed(), chunks(), drop(), every(), filter(), find(), flatMap(), forEach(), includes(), join(), map(), reduce(), some(), take(), toArray(), windows(), [Symbol.dispose](), [Symbol.iterator]().

Library declarations
JavaScript
// Iterator helper (static)
Iterator.from(object)

// object : iterable or iterator
// returns: an Iterator (or the same object if it already is one)

Parameters

ParameterDescription
objectRequired. An iterable (array, Set, string, generator result, ...) or an object with a next() method. The method obtains or wraps an iterator from it.

Return Value

Return ValueDescription
IteratorA proper iterator with helpers. If object is already an instance of Iterator, that same object is returned.

JavaScript Examples

Example 1 — Make an Iterator from an Array

Wrap a small array, read the first value with next(), then collect the rest with toArray().

JavaScript
const it = Iterator.from([10, 20, 30]);

console.log("First: " + it.next().value);
console.log("Rest: " + it.toArray().join(", "));
Try It Yourself

The Try It page first checks that Iterator.from() 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. Wrap the array. Iterator.from([10, 20, 30]) gives a proper Iterator over those numbers.
  2. Read one value. next() returns { value: 10, done: false }, so .value is 10.
  3. Collect the rest. toArray() reads what is left: 20 and 30.

Example 2 — Chain map() after from()

Turn an array into an Iterator, double each number, and finish with toArray().

JavaScript
const doubled = Iterator.from([1, 2, 3])
  .map((n) => n * 2)
  .toArray();

console.log("Doubled: " + doubled.join(", "));
console.log("Length: " + doubled.length);
Try It Yourself

The Try It page first checks that Iterator.from() 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. Start from data. from() turns the array into an Iterator with helpers.
  2. Transform. map((n) => n * 2) yields 2, 4, 6 without changing the original array.
  3. Finish. toArray() collects the mapped values so you can print them.

Example 3 — Wrap a Generator Result

Pass a generator call to Iterator.from(), take the first two values, and print them.

JavaScript
function* count() {
  yield 1;
  yield 2;
  yield 3;
}

const firstTwo = Iterator.from(count()).take(2).toArray();

console.log("First two: " + firstTwo.join(", "));
console.log("Has 3: " + firstTwo.includes(3));
Try It Yourself

The Try It page first checks that Iterator.from() 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. Generator call. count() returns an iterator of 1, 2, 3.
  2. Wrap and limit. Iterator.from(count()).take(2) keeps only the first two values.
  3. Check. The array is [1, 2], so includes(3) is false.

Browser & Runtime Support

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

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.from() 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 turns an iterable or a plain iterator into a proper Iterator. After that, you can chain helpers such as map(), filter(), take(), and toArray().
Array.from() builds a full array right away. Iterator.from() keeps a lazy iterator so you can transform values one by one and only collect them when you need to.
Not always. Array.prototype.values() already returns a built-in iterator. Use from() when you have a custom iterable, a plain next() object, or you want a clear starting point for helper chains.
Yes. Strings are iterable, so Iterator.from("hi") yields "h" then "i". You can then map or take those characters like any other iterator.
If it is already an instance of Iterator, from() returns that same object. You do not get a second wrapper in that case.

Next: Iterator.zip()

Learn how to walk several iterables side by side and get matching pairs as arrays.

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