bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/JavaScript/Working with Data
JavaScript•Working with Data

JavaScript Set Logic

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 136Edge 136Firefox 129Safari 18.2Opera 120
Apr 2025Apr 2025Aug 2024Des 2024May 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:

Example

const 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

const 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

const 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

const 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

const A = new Set(['a','b','c']);
const B = new Set(['b','c','d']);
let answer = A.isDisjointFrom(B);

Learn More

JavaScript Sets

JavaScript Set Methods

JavaScript Weak Sets

JavaScript Set Reference

JavaScript Maps

Previous

JavaScript Array Search

Next

JavaScript WeakMap

This chapter

Overview
37

Lessons

216m

Read time

1. JavaScript Strings2. JavaScript Numbers3. JavaScript Dates4. JavaScript Arrays5. JavaScript Sets6. JavaScript Maps7. JavaScript Math Object8. JavaScript RegExp9. JavaScript String Templates10. JavaScript Number Methods11. JavaScript Date Formats12. JavaScript Array Methods13. JavaScript Set Methods14. JavaScript Map Methods15. JavaScript Random16. JavaScript RegExp Flags17. JavaScript String Methods18. JavaScript Number Properties19. JavaScript Get Date Methods20. JavaScript Array Search21. JavaScript Set Logic22. JavaScript WeakMap23. RegExp Character Classes24. JavaScript String Search25. JavaScript Bitwise Operations26. JavaScript Set Date Methods27. JavaScript Array Sort28. JavaScript WeakSet29. RegExp Meta Characters30. JavaScript BigInt31. JavaScript Array Iterations32. Regular Expression Assertions33. JavaScript Array Const34. RegExp Quantifiers35. JavaScript RegExp Patterns36. JavaScript RegExp Objects37. RegExp Methods

On this page

Browser SupportThe union() MethodThe intersection() MethodThe difference() MethodThe symmetricDifference() MethodThe isSubsetOf() MethodThe isSupersetOf() MethodThe isDisjointFrom() Method