JavaScript Iterator Iterator.zip() Method

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

Definition

Iterator.zip(iterables) walks several iterables together. Each step yields one array: the next value from every input, in the same order as the inputs.

By default it uses mode "shortest": when any input runs out, the zip stops. You can also pass options for "longest" or "strict" when lengths differ.

Remember
Iterator.zip([a, b])

step 1 → [a1, b1]
step 2 → [a2, b2]

default mode: "shortest"
stops when any input is done

use zipKeyed() when you want named keys

Syntax

Pass one iterable of iterables (often an array of iterators). Collect with toArray() when you want every pair.

JavaScript
const a = [1, 2].values();
const b = ["x", "y"].values();

const pairs = Iterator.zip([a, b]).toArray();

console.log(JSON.stringify(pairs));   // [[1,"x"],[2,"y"]]
CallWhat it does
Iterator.zip([a, b])Pair values from a and b into arrays.
Iterator.zip([a, b]).toArray()Collect every pair into one array.
Iterator.zip([a, b], { mode: "longest" })Keep going until the longest input ends; shorter ones pad with undefined by default.
Iterator.zipKeyed({ a, b })Same idea, but each step is an object with keys.

A newer JavaScript static method on Iterator. Call it as Iterator.zip(...). Support is still rolling out, so feature-detect before you rely on it. Siblings: Iterator.concat(), Iterator.from(), Iterator.zipKeyed(), chunks(), drop(), every(), filter(), find(), flatMap(), forEach(), includes(), join(), map(), reduce(), some(), take(), toArray(), windows(), [Symbol.dispose](), [Symbol.iterator]().

Library declarations
JavaScript
// Newer Iterator static method
Iterator.zip(iterables)
Iterator.zip(iterables, options)

// iterables : iterable of iterables (not a bare iterator)
// options   : optional { mode, padding }
// returns   : a new Iterator of arrays

Parameters

ParameterDescription
iterablesRequired. An iterable whose items are themselves iterable (or iterators). A common choice is an array such as [iterA, iterB]. It must be finite. Strings as top-level zip inputs are rejected; wrap them with Iterator.from() first.
optionsOptional. An object with mode ("shortest", "longest", or "strict") and, for "longest", an optional padding iterable.

Return Value

Return ValueDescription
IteratorA new iterator. Each value is an array with one item from each input at that position.

JavaScript Examples

Example 1 — Pair Values from Two Iterators

Zip two short array iterators and print each pair as JSON text.

JavaScript
const nums = [1, 2].values();
const letters = ["a", "b"].values();

const pairs = Iterator.zip([nums, letters]).toArray();

console.log("Pairs: " + JSON.stringify(pairs));
console.log("Count: " + pairs.length);
Try It Yourself

The Try It page first checks that Iterator.zip() 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. Two iterators. .values() gives one number stream and one letter stream.
  2. Zip them. Iterator.zip([nums, letters]) yields [1, "a"], then [2, "b"].
  3. Collect. toArray() stores both pairs so JSON.stringify can print them.

Example 2 — Stop at the Shortest Input

Zip a longer list with a shorter one. By default, leftover values on the long side are ignored.

JavaScript
const left = [1, 2, 3].values();
const right = ["x", "y"].values();

const pairs = Iterator.zip([left, right]).toArray();

console.log("Pairs: " + JSON.stringify(pairs));
console.log("Dropped 3: true");
Try It Yourself

The Try It page first checks that Iterator.zip() 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. Unequal lengths. Left has three numbers; right has two letters.
  2. Default mode. "shortest" stops when right is done, so only two pairs are made.
  3. Leftover. The number 3 is never paired, which the second log line states clearly.

Example 3 — Zip Three Iterables Together

Combine three short iterators. Each step is an array of three values.

JavaScript
const a = Iterator.from([1, 2]);
const b = Iterator.from(["p", "q"]);
const c = Iterator.from([true, false]);

const rows = Iterator.zip([a, b, c]).toArray();

console.log("First: " + JSON.stringify(rows[0]));
console.log("Second: " + JSON.stringify(rows[1]));
Try It Yourself

The Try It page first checks that Iterator.zip() 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. Three sources. Each list is turned into an Iterator with Iterator.from().
  2. One zip. Every step pulls one value from each source into a length-3 array.
  3. Print both rows. The first triple is [1, "p", true]; the second is [2, "q", false].

Browser & Runtime Support

Iterator.zip() is a newer Iterator static method for pairing values from several iterables. Support is still rolling out, so feature-detect first.

✓ Newer · Recent engines

Iterator.zip()

Supported in Chrome 146+, Edge 146+, Firefox 147+, Safari 26.4+, Opera 131+ and Node.js 24+. Internet Explorer never got it.

Recent Standard since
Google Chrome 146+ · Desktop & Mobile
Full support
Microsoft Edge 146+ · Chromium based
Full support
Mozilla Firefox 147+ · Desktop & Mobile
Full support
Apple Safari 26.4+ · macOS & iOS
Full support
Opera 131+ · Chromium based
Full support
Samsung Internet Recent · Android
Supported
Android WebView 146+ · Chromium based
Supported
Node.js 24+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
Iterator.zip() Recent engines

Bottom line: Feature-detect before use. A short manual loop that reads next() from each iterator can stand in on older engines.

Frequently Asked Questions

It walks several iterables at the same time. Each step yields one array with the next value from every input, so you can keep matching items together.
zip() takes one iterable of iterables. An array of iterators is the usual choice. Writing Iterator.zip(a, b) as two separate arguments is not the API.
By default, mode is "shortest": the result stops when any input ends. Use mode "longest" to keep going with padding, or "strict" to throw if lengths differ.
Use zipKeyed() when you want each step to be an object with named keys, such as { id, name }. Use zip() when a plain array pair is enough.
Not as top-level zip inputs in the usual way strings might look tempting. Convert them with Iterator.from("ab") (or similar) so each character is yielded as an iterator value.

Next: Iterator.zipKeyed()

Learn the object form of zip: each step is a keyed object instead of an array.

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

11 people found this page helpful