❌ Remove array duplicates with Set
👋 FYI, this note is over 6 months old. Some of the content may be out of date.
On this page
Using Set
Jump to heading
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]
← Back home