Use a set to remove array duplicates
If you have an array of items that contains duplicates, you can remove them all by spreading the array into a new Set
.
- Code language
- javascript
const array = ['Hello', 'Hi', 'Hello', 'Ciao']; const filtered = [...new Set(array)]; console.log(filtered); // ['Hello', 'Hi', 'Ciao']
Enjoyed this article? You can support us by leaving a tip via Open Collective

Newsletter
Loading, please wait…
Powered by Postmark - Privacy policy