Set methodsBaseline · Newly available
The difference(), intersection(), isDisjointFrom(), isSubsetOf(), isSupersetOf(), symmetricDifference(), and union() methods of the JavaScript Set object performs operations between two sets.
Works in the latest version of every major browser, but older devices may not support it yet. Baseline since Jun 11, 2024.
Browser support
DesktopChrome
1–121Not supported
122+Supportedsince Feb 20, 2024
Current: 155Edge
12–121Not supported
122+Supportedsince Feb 23, 2024
Current: 154Firefox
1–126Not supported
127+Supportedsince Jun 11, 2024
Current: 157Safari
1–16.6Not supported
17+Supportedsince Sep 18, 2023
Current: 27MobileChrome Android
18–121Not supported
122+Supportedsince Feb 20, 2024
Current: 155Firefox Android
4–126Not supported
127+Supportedsince Jun 11, 2024
Current: 157Safari iOS
1–16.6Not supported
17+Supportedsince Sep 18, 2023
Current: 27How to use
Every current browser supports this, but it only became Baseline on Jun 11, 2024. Use it as a progressive enhancement, or keep a fallback if you support older devices.
Example
JS
const a = new Set([1, 2, 3]);
const b = new Set([2, 3, 4]);
a.union(b); // Set {1, 2, 3, 4}
a.intersection(b); // Set {2, 3}
a.difference(b); // Set {1}
a.isSubsetOf(new Set([1, 2, 3, 4])); // trueFeature detection
JS · check before using
if ("difference" in Set || ("prototype" in Set && "difference" in Set.prototype)) {
// Set.difference is available
}Sub-features
Support for each part of the feature (7). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Set.difference | 122 | 122 | 127 | 17 | 122 | 127 | 17 |
| Set.intersection | 122 | 122 | 127 | 17 | 122 | 127 | 17 |
| Set.isDisjointFrom | 122 | 122 | 127 | 17 | 122 | 127 | 17 |
| Set.isSubsetOf | 122 | 122 | 127 | 17 | 122 | 127 | 17 |
| Set.isSupersetOf | 122 | 122 | 127 | 17 | 122 | 127 | 17 |
| Set.symmetricDifference | 122 | 122 | 127 | 17 | 122 | 127 | 17 |
| Set.union | 122 | 122 | 127 | 17 | 122 | 127 | 17 |