# How to remove duplicates from a JavaScript array

> Learn how to remove duplicate values from a JavaScript array in one line by passing it to a Set and spreading the result, which works for any primitives.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-03-12 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/how-to-remove-duplicates-array-javascript/

Let's say you have an array containing a series of primitive values, for example numbers or strings.

Some of those elements are repeated.

Like in this example:

```js
const list = [1, 2, 3, 4, 4, 3]
```

We can generare a new array containing the same values, without the duplicates, in this way:

```js
const uniqueList = [...new Set(list)]
```

`uniqueList` will now be a new array with the values `[1, 2, 3, 4]` in it.

How does this work?

`Set` is a new data structure, introduced in ES6 in 2015, and its main characteristic is to be a container for data that can't be repeated in the same set. [See my full guide on Set here](https://flaviocopes.com/javascript-data-structures-set/). 

By initializing a Set with a destructured array (see the `...` operator before `new Set()`), we pass values and Set automatically removes the duplicates. Then we convert it to an array by wrapping it into square brackets `[]`.

This method works with anything that's not an object: [numbers](https://flaviocopes.com/javascript-number/), [strings](https://flaviocopes.com/javascript-string/), booleans, [symbols](https://flaviocopes.com/javascript-symbols/).
