Which one is a better use of new Set() in JavaScript?

const array = [1, 2, 2, 2, 3, 4, 4, 4, 4, 5]

// first case
const filteredArray1 = new Set([...array])
 
// second case
const filteredArray2 = [...new Set(array)]

console.log(filteredArray1, filteredArray2)

151 thoughts on “Which one is a better use of new Set() in JavaScript?”