JAVASCRIPT EXAMPLE · ARRAYS

Remove Duplicate Values

Set ka use karke repeated array values ko remove karke unique array banao.

Working code

const numbers = [10, 20, 10, 30, 20, 40];

const uniqueNumbers = [...new Set(numbers)];

console.log(uniqueNumbers);
Run Code ▶

Output

[10, 20, 30, 40]

How it works

Set duplicate values store nahi karta, isliye repeated numbers automatically remove ho jate hain.

Spread syntax ... Set ko dobara normal array me convert karta hai.

Try Yourself

const values = ["html", "css", "html", "js", "css"];
const uniqueValues = [...new Set(values)];

console.log(uniqueValues);

Learn this concept

Read JavaScript Arrays Tutorial →