ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

How do you remove duplicates from an array?

Quick answer

Wrap it in a Set and spread back: [...new Set(arr)].

In detail

A Set stores unique values, so converting to a Set and back removes duplicates in one line for primitives. For objects (compared by reference) you need a key-based approach with a Map or filter.

[...new Set([1, 2, 2, 3])];     // [1, 2, 3]
// by key for objects:
const seen = new Set();
users.filter(u => !seen.has(u.id) && seen.add(u.id));

Why interviewers ask this: A quick practical that shows knowledge of Set.

This is 1 of 118+ questions in the JavaScript Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the JavaScript Interview Kit → ₹299

Full kit

JavaScript Interview Kit · ₹299

Get it →