Ben Borgers

How to remove duplicates in an array in JavaScript

May 8, 2020

Let's say you have this array:

const myArray = ["red", "blue", "green", "blue", "blue", "orange", "green"]

But you only want each item to appear once.

Here's how you turn that array into an array where each item only appears once.

const uniqueArray = [...new Set(myArray)]

More blog posts

Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iā€™m working on!

Twitter ↗ RSS feed ↗