Start of main content
# JavaScript Array Set Operations

Mathematical set operations can be easily applied to JavaScript arrays. Learn how to use the union, intersection, difference, and symmetric difference operations with this snippet collection.

### Array union

Returns every element that exists in any of the two arrays at least once.

JavaScript, Array · Oct 22, 2020

### Array intersection

Returns the elements that exist in both arrays, filtering duplicate values.

JavaScript, Array · Oct 20, 2020

### Array difference

Calculates the difference between two arrays, without filtering duplicate values.

JavaScript, Array · Oct 19, 2020

### Array symmetric difference

Returns the symmetric difference between two arrays, without filtering out duplicate values.

JavaScript, Array · Oct 22, 2020

### Mapped array union

Returns every element from both arrays that exists at least once after applying the provided function.

JavaScript, Array · Oct 22, 2020

### Mapped array intersection

Returns the elements that exist in both arrays, after applying the provided function to each array element of both.

JavaScript, Array · Oct 20, 2020

### Mapped array difference

Returns the difference between two arrays, after applying the provided function to each array element of both.

JavaScript, Array · Oct 19, 2020

### Mapped array symmetric difference

Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.

JavaScript, Array · Oct 22, 2020

### Array union based on function

Returns every element that exists in any of the two arrays at least once, using a provided comparator function.

JavaScript, Array · Oct 22, 2020

### Array intersection based on function

Returns the elements that exist in both arrays, using a provided comparator function.

JavaScript, Array · Oct 20, 2020

### Array difference based on function

Filters out all values from an array for which the comparator function does not return

`true`

.JavaScript, Array · Oct 22, 2020

### Array symmetric difference based on function

Returns the symmetric difference between two arrays, using a provided function as a comparator.

JavaScript, Array · Oct 18, 2020