Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

How do you remove duplicates from an array with Set?

Do you know what will be the output of this code?

JavaScript
console.log([...new Set([1, 1, 2, 3, 3])]);
Show answer and explanation

The answer is [1, 2, 3].

Set ignores values it already has. Spreading it into [...] turns it back into an array, keeping the original order.

Take the full quiz Next question →

More Arrays questions

  1. Does the spread operator make a deep copy?
  2. When do default parameters apply in JavaScript?
  3. What is the difference between ?? and || in JavaScript?
  4. How does optional chaining short-circuit in JavaScript?
  5. When do destructuring default values apply?

Related topics