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]
I'm sharing everything I learn while building a software company. Join my newsletter to receive advice and opportunities that I never post publicly. Or learn more about me?