freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #46 of 61

set · unique values

LambdaVSThe Mutator
Lambda saysSet stores unique values — adding a duplicate is a no-op.

A Set holds each value once. Add with add, check with has, count with .size. The fastest way to dedupe an array is [...new Set(arr)]. Sets are iterable and keep insertion order, making them great for membership tests and unique collections.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleDedupe an array with duplicates using a Set.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const unique=[...new Set([1,1,2,3,3,3,4])];
document.getElementById('o').textContent=unique.join(' ');</script></body></html>
▶ Open the interactive comic issue
‹ Map · Ordered Key-Value StoreWeakmap · Weakset · Gc-Friendly ›