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']

Demo permalink