JavaScript Iterator Iterator.zipKeyed() Method

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

Definition

Iterator.zipKeyed({ a: iterA, b: iterB }) walks the named iterables together. Each step yields one object such as { a: valueFromA, b: valueFromB }.

It is the same idea as Iterator.zip(), but keys come from your property names instead of array indexes. The default mode is still "shortest".

Remember
Iterator.zipKeyed({ a: iterA, b: iterB })

step 1 → { a: a1, b: b1 }
step 2 → { a: a2, b: b2 }

keys come from the object you pass
default mode: "shortest"

use zip() when a plain array pair is enough

Syntax

Pass one object whose values are iterables. Collect with toArray() when you want every row.

JavaScript
const rows = Iterator.zipKeyed({
  id: [1, 2].values(),
  name: ["Ann", "Bo"].values()
}).toArray();

console.log(JSON.stringify(rows[0]));   // {"id":1,"name":"Ann"}
CallWhat it does
Iterator.zipKeyed({ a, b })Pair values into objects with keys a and b.
Iterator.zipKeyed(obj).toArray()Collect every keyed row into an array.
Iterator.zipKeyed(obj, { mode: "longest" })Keep going until the longest input ends.
Iterator.zip([a, b])Same walk, but each step is an array instead of an object.

A newer JavaScript static method on Iterator. Call it as Iterator.zipKeyed(...). Support is still rolling out, so feature-detect before you rely on it. Siblings: Iterator.concat(), Iterator.from(), Iterator.zip(), 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.zipKeyed(iterables)
Iterator.zipKeyed(iterables, options)

// iterables : object of named iterables
// options   : optional { mode, padding }
// returns   : a new Iterator of objects

Parameters

ParameterDescription
iterablesRequired. A plain object. Each property name becomes a key in the result objects. Each property value must be iterable (or an iterator). Strings need Iterator.from() when you want character streams.
optionsOptional. An object with mode ("shortest", "longest", or "strict") and, for "longest", an optional padding object with the same keys.

Return Value

Return ValueDescription
IteratorA new iterator. Each value is an object with the same keys as iterables, filled with the next value from each input.

JavaScript Examples

Example 1 — Zip into Objects with Keys

Pair ids and names. Each step is an object you can read by key.

JavaScript
const rows = Iterator.zipKeyed({
  id: [1, 2].values(),
  name: ["Ann", "Bo"].values()
}).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.zipKeyed() 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. Name the streams. Keys id and name label the two iterators.
  2. Zip by key. Each step builds one object with those same keys.
  3. Print rows. JSON.stringify shows {"id":1,"name":"Ann"} then the second person.

Example 2 — Stop When One Key Runs Out

Give one key more values than another. Default mode keeps only the matching prefix.

JavaScript
const rows = Iterator.zipKeyed({
  a: [1, 2, 3].values(),
  b: ["x", "y"].values()
}).toArray();

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

The Try It page first checks that Iterator.zipKeyed() 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 inputs. Key a has three values; key b has two.
  2. Shortest mode. Zipping stops when b ends, so only two objects are made.
  3. Check the count. rows.length is 2, and the leftover 3 is not included.

Example 3 — Zip Streams from Iterator.from()

Build each named stream with Iterator.from(), then zip them into keyed rows.

JavaScript
const rows = Iterator.zipKeyed({
  n: Iterator.from([10, 20]),
  label: Iterator.from(["ten", "twenty"])
}).toArray();

console.log("Labels: " + rows.map((r) => r.label).join(", "));
console.log("Sum: " + rows.reduce((s, r) => s + r.n, 0));
Try It Yourself

The Try It page first checks that Iterator.zipKeyed() 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 each list. Iterator.from() makes proper iterators for numbers and labels.
  2. Zip by name. Each row has n and label filled from the same position.
  3. Use the keys. Map over label for the text line, and sum n to get 30.

Browser & Runtime Support

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

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.zipKeyed() 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 named iterables together. Each step yields one object whose keys match the names you passed, with the next value from each iterable.
zip() yields arrays like [1, "Ann"]. zipKeyed() yields objects like { id: 1, name: "Ann" }. Use zipKeyed() when named fields are clearer than positions.
Pass one object: Iterator.zipKeyed({ a: iterA, b: iterB }). Property names become result keys. Property values must be iterable or iterators.
By default, mode is "shortest", so zipping stops when any named input ends. Use mode "longest" with optional padding, or "strict" to throw when lengths differ.
Yes. The result is an Iterator, so you can map, filter, take, or call toArray() on it, just like other Iterator helper results.

Next: chunks()

Learn how to split an iterator into fixed-size groups with the chunks() helper.

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

10 people found this page helpful