JavaScript Set Logic
[JavaScript 2025](/js/js2025.asp) is fully supported in all modern browsers since May 2025:
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
Example Code
javascriptconst 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
Example Code
javascriptconst 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:
Example
Example Code
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
const C = A.difference(B);The symmetricDifference() Method
The symmetricDifference() method returns the symmetric difference between to sets.
The symmetricDifference() method returns a new set containing elements which are in this set or in the argument set, but not in both:
Example
Example Code
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
const C = A.symmetricDifference(B);The isSubsetOf() Method
The isSubsetOf() method returns true if all elements in this set is also elements in the argument set:
Example
Example Code
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
let answer = A.isSubsetOf(B);The isSupersetOf() Method
The isSupersetOf() method returns true if all elements in the argument set are also in this set:
Example
Example Code
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
let answer = A.isSupersetOf(B);The isDisjointFrom() Method
The isDisjointFrom() method returns true if this set has no elements in common with the argument set:
Example
Example Code
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
let answer = A.isDisjointFrom(B);Interactive Code Examples
JS Example 1
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
const C = A.union(B);JS Example 2
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
const C = A.intersection(B);JS Example 3
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
const C = A.difference(B);JS Example 4
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
const C = A.symmetricDifference(B);JS Example 5
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
let answer = A.isSubsetOf(B);JS Example 6
javascriptconst A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
let answer = A.isSupersetOf(B);