Medium javascript

Remove duplicates

Problem

Remove duplicates from [1,2,2,3,3,3,4] preserving order.

Hints
  • new Set(arr) then spread to array

Your practice code

Ready — edit the code above and click Run.

Solution

const arr = [1, 2, 2, 3, 3, 3, 4];
console.log([...new Set(arr)]);

Try solving on your own first, then reveal the official answer.

Explanation

Set keeps unique values; spread back to array. Interview follow-up: implement without Set.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details