- Instant help with your JavaScript coding problems

Remove duplicates from array in JavaScript

Question:
How to remove duplicates from array in JavaScript?
Answer:
const myArray = [2,5,6,2,2,4,5,3,3];

const uniqueArray = [...new Set(myArray)];

console.log(uniqueArray);
Description:

To remove all duplicates from an array you can use the Set object and spread operator. The Set constructor lets you create Set objects that store unique values. After the Set object is created you can create a new array from it using the spread syntax ...

Reference:
The Set reference
Share "How to remove duplicates from array in JavaScript?"