Set operator to remove duplicate array elements

const arr = [1, 2, 2, 3, 4];
console.log([...new Set(arr)]);
// Array(4) [ 1, 2, 3, 4 ]