JavaScript Set.prototype.intersection() Method
The intersection() method returns a new Set with only the values that both sets have in common.
Description
The intersection() method returns a new set containing the values that are in both sets.
It's useful for finding common items, such as tags shared by two articles, or features supported by both of two devices. If you only need to know whether the sets share anything, isDisjointFrom() is more direct.
The argument can be any set-like object, meaning one with a size property and has() and keys() methods, such as another Set or a Map (whose keys are used). Arrays aren't set-like, so wrap them first: new Set(array). The original sets are never changed, and the result keeps the order of the set the method was called on.
Syntax
set.intersection(other)Parameters
- otherAnother Set, or a set-like object.
Return Value
A new Set with only the values found in both sets.
Example
Browser Support
The following information will show you the current browser support for the Set.prototype.intersection() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





