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]

Want more?

My newsletter sends rarely. It's where I share updates on the best of my writing: introverted entrepreneurship, esoteric mindset tips, notes from great books, and automating businesses as a solo-owner so they run by themselves. Want to join?