bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/JavaScript/Working with Data
JavaScript•Working with Data

JavaScript Set Logic

Concept visual

JavaScript Set Logic

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Logic Set Methods

In JavaScript 2025, 7 new logical methods were added to the Set object: union() difference() intersection() isDisjointFrom() isSubsetOf() isSupersetOf() symmetricDifference()

Browser Support

Set Logic is an ECMAScript 2025 feature. JavaScript 2025 is fully supported in all modern browsers since

May 2025

Chrome

136

Edge

136

Firefox

129

Safari

18.2

Opera

120

Apr 2025

Apr 2025

Aug 2024

Des 2024

May 2025

The union() Method

The union()

method returns the union of two sets.

The union()

method returns a new set containing the elements which are in this set, or in the argument set, or in both:

Example

const A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
const C = A.union(B);

The intersection() Method

The intersection()

method returns the intersection of two sets.

The intersection()

method returns a new set containing the elements which are in this set and in the argument set:

Example

const A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
const C = A.intersection(B);

The difference() Method

The difference()

method returns the difference between two sets.

The difference()

method returns a new set containing elements which are in this set but not in the argument set:

Previous

JavaScript Array Search

Next

JavaScript WeakMap