Get to know MDN better
Since June 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The intersection() method of Set instances takes a set and returns a new set containing elements in both this set and the given set.
A Set object, or set-like object.
A new Set object containing elements in both this set and the other set.
In mathematical notation, intersection is defined as:
A∩B={x∊A∣x∊B}A\cap B = \{x\in A\mid x\in B\}And using Venn diagram:
intersection() accepts set-like objects as the other parameter. It requires this to be an actual Set instance, because it directly retrieves the underlying data stored in this without invoking any user code. Then, its behavior depends on the sizes of this and other:
Because of this implementation, the efficiency of intersection() mostly depends on the size of the smaller set between this and other (assuming sets can be accessed in sublinear time). The order of elements in the returned set is the same as that of the smaller of this and other.
The following example computes the intersection between the set of odd numbers (<10) and the set of perfect squares (<10). The result is the set of odd numbers that are perfect squares.
| ECMAScript® 2027 Language Specification # sec-set.prototype.intersection |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.