For AI agents: the complete documentation index is available at /tc39-atlas/en/llms.txt, the full documentation bundle is available at /tc39-atlas/en/llms-full.txt, and this page is available as Markdown at /tc39-atlas/en/proposals/year/pending/proposal-array-zip.md.
  • English
  • Array.zip and Array.zipKeyed S1

    Proposal details
    Proposal overview

    This proposal adds static methods Array.zip and Array.zipKeyed to synchronize iteration over multiple arrays, based entirely on the API and semantics of Iterator.zip and Iterator.zipKeyed from proposal-joint-iteration. It addresses the common preference for arrays over iterators for small finite lists and improves ergonomics compared to converting iterators via .toArray() and Iterator.from().

    Note

    The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.

    proposal-array-zip

    A TC39 proposal to synchronize the iteration of multiple arrays.

    This proposal is based entirely on https://github.com/tc39/proposal-joint-iteration - in other words, this proposal is Iterator.zip and Iterator.zipKeyed for arrays.

    Stage: 1

    Specification: https://tc39.es/proposal-array-zip/

    Motivation / Problem

    Despite iterators existing for over a decade, it is still exceedingly common to use - and prefer - arrays over iterators, especially for small finite lists. They're simpler to work with, often more performant, and more broadly compatible with ecosystem libraries.

    One can now always turn any iterator into an array with .toArray() - which is useful, but not ergnomic, especially when combined with the need to wrap the value in Iterator.from() before accessing iterator helpers.

    Solution

    Add Array.zip and Array.zipKeyed static methods to the Array constructor.

    Rationales

    • the method names, APIs, and semantics must match https://github.com/tc39/proposal-joint-iteration, to avoid confusion
    • this includes accepting iterables, like Array.from and Array.fromAsync
    • Adding Array.prototype methods is the most frequent cause of web compatibility issues, and browsers have expressed an unwillingness to even attempt adding more in the future - thus, they must be static