set.intersection(other) returns a new Set with the values that are in both Sets. It answers the question: "What do these two collections have in common?"
Neither Set is changed. The argument can be another Set or a set-like object such as a Map, but not an array. The result has the same values whichever Set you start from, but the order of the values can differ.
Remember
a.intersection(b) → values that are in a AND in b
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
a.intersection(b) → {3, 4}
b.intersection(a) → {3, 4} (same values)
a and b stay unchanged
Syntax
Call it on a Set and pass another Set. Read the answer from the new Set that comes back.
JavaScript
const mine = new Set(["js", "css", "html"]);
const yours = new Set(["css", "python", "js"]);
const common = mine.intersection(yours);
console.log(Array.from(common).join(", ")); // js, css
console.log(mine.size); // 3 (unchanged)
Call
What it does
a.intersection(b)
A new Set with the values that are in both a and b.
a.intersection(b).size
How many values they share. 0 means nothing in common.
a.intersection(b).intersection(c)
Chain calls to find values that are in all three Sets.
a.intersection(new Set(array))
Turn an array into a Set first, because an array is not accepted.
// ECMAScript 2025
Set.prototype.intersection(other)
// other : a Set, or a set-like object (needs size, has() and keys())
// returns: a new Set
// throws : TypeError if other is not set-like (for example an array)
Parameters
Parameter
Description
other
Required. A Set, or any set-like object: an object with a numeric size and the methods has() and keys(). A Map is set-like. An array is not, so convert it with new Set(array).
Return Value
Return Value
Description
Set
A new Set with the values that are in both Sets. It is empty when nothing is shared. Both original Sets stay as they were.
TypeError (thrown)
other is not set-like, for example an array or a number.
JavaScript Examples
Example 1 — Find the Values Two Sets Share
Two people list the skills they know. Find the skills they have in common.
The Try It page first checks that Set.prototype.intersection() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.
How It Works
Two Sets of skills.mine and yours each have three values, and two of them (js and css) appear in both.
Keep what is shared.mine.intersection(yours) returns a new Set with only js and css.
Originals are safe. Both source Sets still have 3 values, because the method never changes them.
Example 2 — Order and Special Cases
A larger Set can give its common values in the smaller Set's order. Then see what happens with no overlap and with the same Set.
JavaScript
const big = new Set([1, 2, 3, 4]);
const small = new Set([4, 3]);
console.log("big, small: " + Array.from(big.intersection(small)).join(", "));
console.log("small, big: " + Array.from(small.intersection(big)).join(", "));
const odd = new Set([1, 3, 5]);
const even = new Set([2, 4, 6]);
console.log("No overlap: " + odd.intersection(even).size);
console.log("With itself: " + odd.intersection(odd).size);
big, small: 4, 3
small, big: 4, 3
No overlap: 0
With itself: 3
The Try It page first checks that Set.prototype.intersection() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.
How It Works
Same values, maybe a new order. Both calls find 3 and 4. When the starting Set is larger, the result can follow the smaller Set, so you see 4, 3 in both lines.
No overlap. Odd and even numbers share nothing, so the result is an empty Set with size 0.
With itself. A Set shares every value with itself, so the result has all 3 values.
Example 3 — Chain Calls and Use a Map
Find values that are in three Sets by chaining. A Map can be the argument too, and its keys are compared.
JavaScript
const a = new Set([1, 2, 3, 4, 5]);
const b = new Set([2, 3, 4, 8]);
const c = new Set([3, 4, 9]);
const all = a.intersection(b).intersection(c);
console.log("In all three: " + Array.from(all).join(", "));
const prices = new Map([[3, "low"], [5, "high"], [7, "mid"]]);
const found = a.intersection(prices);
console.log("In the Map keys: " + Array.from(found).join(", "));
The Try It page first checks that Set.prototype.intersection() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.
How It Works
First step.a.intersection(b) keeps 2, 3, 4, a new Set.
Second step. Calling intersection(c) on that new Set keeps only the values that are also in c: 3, 4.
A Map as the argument. A Map is set-like, so its keys 3, 5, 7 are compared with a, and 3, 5 are in both.
Compatibility
Browser & Runtime Support
Set.prototype.intersection() is one of the new Set methods added in ES2025. It works in current browsers and in Node.js 22 or newer, but not in older versions.
✓ Newer · ES2025
set.intersection()
Supported in Chrome 122+, Edge 122+, Firefox 127+, Safari 17+, Opera 108+ and Node.js 22+. Internet Explorer never got it.
ES2025Standard since
Google Chrome122+ · Desktop & Mobile
Full support
Microsoft Edge122+ · Chromium based
Full support
Mozilla Firefox127+ · Desktop & Mobile
Full support
Apple Safari17+ · macOS & iOS
Full support
Opera108+ · Chromium based
Full support
Samsung Internet26+ · Android
Supported
Android WebView122+ · Chromium based
Supported
Node.js22+ · Server runtime
Supported
DenoRecent versions · JavaScript runtime
Supported
BunRecent versions · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
set.intersection()Recent browsers
Bottom line: Check support with typeof Set.prototype.intersection === "function". For older browsers, the same result can be made with the spread syntax and filter(), or with a loop.
Frequently Asked Questions
It returns a new Set with the values that are in both Sets, so it finds what two collections have in common. Neither original Set is changed.
The same values are always returned, but their order can follow the smaller Set when you start from the larger one. Do not depend on the order. Sort the values after converting to an array if you need a fixed order.
No. The argument must be a Set or a set-like object, such as a Map, because the method needs size, has() and keys(). An array throws a TypeError. Use new Set(array) to convert it first.
Chain the calls: a.intersection(b).intersection(c). Each call returns a new Set, so you can call intersection() on the result again.
Use filter() on the first Set: new Set([...a].filter((x) => b.has(x))). It gives the same values and works everywhere that Set works.