Skip to content

tc39/proposal-set-methods

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

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 3.

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.

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