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/proposal-iterator-join.md.
  • English
  • Iterator Join S3

    Proposal details
    Proposal overview

    This proposal aims to simplify concatenating the contents of any iterable into a string. It introduces Iterator.prototype.join, which mirrors Array.prototype.join but operates on iterators, avoiding intermediate allocations or array conversions.

    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.

    Iterator Join

    A proposal to add to JavaScript a means to concatenate the contents of an iterator into a string.

    Status

    Authors: Kevin Gibbons

    Champions: Kevin Gibbons

    This proposal is at stage 3 of the TC39 process: it has a specification and test262 tests and is ready for implementations.

    Motivation

    Joining a list of strings into a single string for display or other reasons is a very common operation. If you have an array, it's trivial: just call .join(sep). If you have any other iterable, you can either do Iterator.from(it).reduce((a, b) => a + sep + b) (and pay the cost of allocating all the intermediate strings, plus this breaks on empty iterators), or Array.from(it).join(sep) (and pay the cost of converting the whole thing to an Array).

    We should make that easier.

    This came up during the original iterator helpers proposal and later on the Discourse.

    Proposal

    While in principle there are various ways to solve this problem, the obvious one is to add Iterator.prototype.join which works exactly like Array.prototype.join except that it operates on its receiver as an iterator rather than as an Array. That is what is currently specified.