How to Remove Duplicates From an Array in JavaScript

Remove duplicate values from a JavaScript array using Set, filter(), or reduce(), including how to dedupe arrays of objects by a key.

Published September 16, 2026

The simplest way to remove duplicate primitive values from an array is to pass it through a Set, which only stores unique values, then convert it back to an array.

const unique = [...new Set([1, 2, 2, 3, 3, 3])]
// [1, 2, 3]

Steps

  1. Wrap the array in `new Set(array)` — Set automatically discards duplicate values
  2. Spread the Set back into an array with `[...set]` or `Array.from(set)`

How it works

Set uses the SameValueZero algorithm for equality, which behaves like === except it treats NaN as equal to itself. This makes it reliable for deduping numbers, strings, and booleans.

Things to watch for

  • Set only compares primitives by value — two different objects with identical properties are still considered distinct
  • To dedupe an array of objects by a specific field, use a Map keyed by that field: [...new Map(arr.map(o => [o.id, o])).values()]

FAQ

How do I remove duplicate objects from an array?

Set won't work directly since objects compare by reference. Use a Map keyed by a unique property: [...new Map(items.map(i => [i.id, i])).values()].

More JavaScript articles