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?"
Related snippets:
- Check if an array contains a value
- Append an array to another in JavaScript
- Get the first element of an array in JavaScript
- Convert Map values to array in JavaScript
- Convert array to comma separated string using JavaScript
- Get the minimum value in an array using JavaScript
- Get the maximum value in an array using JavaScript
- Remove duplicates from array in JavaScript
- Split a string into words
- Use foreach in JavaScript
Tags:
set, array, unique, duplicates, remove Technical term:
Remove duplicates from array in JavaScript