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/2025/proposal-set-methods.md.
  • English
  • New Set methods S4

    Proposal details
    Proposal overview

    This proposal adds set operation methods like union, intersection, and difference to JavaScript's built-in Set prototype, solving the need for common set operations without third-party libraries. It specifies seven methods, all requiring arguments that have a numeric size property and keys and has methods.

    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.

    Set Methods for JavaScript

    This is a proposal to add methods like union and intersection to JavaScript's built-in Set class.

    It is currently at stage 4: it has been added to the specification. This repository is no longer active.

    Original readme follows.

    Proposal

    This would add the following methods:

    • Set.prototype.intersection(other)
    • Set.prototype.union(other)
    • Set.prototype.difference(other)
    • Set.prototype.symmetricDifference(other)
    • Set.prototype.isSubsetOf(other)
    • Set.prototype.isSupersetOf(other)
    • Set.prototype.isDisjointFrom(other)

    These methods would all require their arguments to be a Set, or at least something which looks like a Set in terms of having a numeric size property as well as keys and has methods.

    See details.md for details of current decisions made in this proposal.

    Rendered spec text is available here.

    The proposal was originally authored by Michał Wadas and later championed by Sathya Gunasekaran and Kevin Gibbons.

    Implementations

    This proposal is ready for engines to implement and ship. See this issue for current status.

    TC39 meeting notes

    (Semi)relevant previous discussions

    Comparison with other languages

    See other languages document to get overview of Set methods in other languages.

    Naming

    See naming bikeshedding document for details.

    We decided to choose:

    • Symmetric difference - symmetricDifference
    • Intersection - intersection
    • Union - union
    • Difference - difference

    Polyfills