- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Set Operations
JavaScript Map & Set
JavaScript Set Operations
Sets can be combined to find values in common, or values in one but not the other.
These are the classic set operations from mathematics.
Each takes one line using spread and filter.
Example
Example
javascript
const a = new Set([1, 2, 3]);
const b = new Set([2, 3, 4]);
const union = new Set([...a, ...b]);
console.log([...union].join(","));