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 isDisjointFrom() method of Set instances takes a set and returns a boolean indicating if this set has no elements in common with the given set.
A Set object, or set-like object.
true if this set has no elements in common with the other set, and false otherwise.
Two sets are disjoint if they have no elements in common. In mathematical notation:
A is disjoint from B⇔A∩B=∅A\text{ is disjoint from }B \Leftrightarrow A\cap B = \emptyAnd using Venn diagram:
isDisjointFrom() 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 isDisjointFrom() mostly depends on the size of the smaller set between this and other (assuming sets can be accessed in sublinear time).
The set of perfect squares (<20) is disjoint from the set of prime numbers (<20), because a perfect square is by definition decomposable into the product of two integers, while 1 is also not considered a prime number:
The set of perfect squares (<20) is not disjoint from the set of composite numbers (<20), because all non-1 perfect squares are by definition composite numbers:
| ECMAScript® 2027 Language Specification # sec-set.prototype.isdisjointfrom |
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.