Remove duplicates from array

Need to remove duplicate values from an array in JavaScript? This code snippet uses the Set constructor in JavaScript to do just that.

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.