Ben Borgers / Posts /

How to remove duplicates in an array in JavaScript

January 24, 2021 by @benborgers

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)]

A quick favor: was anything I wrote incorrect or misspelled, or do you still have questions? Please use this form to let me know or ask for help!

Loading...