Pulling unique values from a JavaScript array

June 17, 2018

This is nice shorthand for pulling unique values from an array:

const uniqueItems = [...new Set(items)]

You can use it like so:

const items = [1, 1, 2, 2, 3, 3]
const uniqueItems = [...new Set(items)]
console.log(uniqueItems) // [1, 2, 3]