Remove duplicates from array

By Hunter Becton on July 21, 2022

const removeDuplicates = (arr) => [...new Set(arr)];

console.log(removeDuplicates([1, 2, 3, 3, 4, 4, 5, 5, 6]));
// Result: [ 1, 2, 3, 4, 5, 6 ]

How to use

Pass an array into the removeDuplicates() function and get a new array returned with duplicates removed.