/
๐Ÿšš

Remove array duplicates

javascript
Table of contents
  • Using Set

Using Set

js
const array = ['๐Ÿ‘', 1, 2, '๐Ÿ‘', '๐Ÿ‘', 3]
// Step 1
const uniqueSet = new Set(array)
// Set { '๐Ÿ‘', 1, 2, 3 }
// Step 2
const backToArray = [...uniqueSet]
// ['๐Ÿ‘', 1, 2, 3]
// or Step 1
const uniqueSet = [...new Set(array)]
// ['๐Ÿ‘', 1, 2, 3]

Source: samanthaming.com/tidbi...cates

Want to make your own site like this?
Try gatsby-theme-code-notes by Zander Martineau.
Notes on code. My second brain, by Zander Martineau.