Home Blog Links About Notes

TILs, snippets—my digital code garden 🌱.

All notes 11ty a11y ai animation api backend cheatsheet cli computer-science cpp css cypress deno dev devops git golang graphql html interview javascript messaging networking node performance php python questions react rust services sql storybook svelte sveltekit testing typescript typography vscode

❌Remove array duplicates with Set

https://www.samanthaming.com/tidbits/43-3-ways-to-remove-array-duplicates
1 Dec 2023
javascript
On this page
  1. Using Set

Using Set

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]
> cd ..
Feeds Colophon Worklog Now Uses Notes GitHub Bluesky Mastodon

© 2026 Zander Martineau • #eec9b70 • This site is always under construction. 🚧