JavaScript · Map · Set · WeakMap · WeakSet
Map & Set,
finally understood
The underused siblings of Array and Object. Deduplication, fast lookups, frequency counts, and garbage-collection-safe caching — all animated with real scenarios.
// Map — any key type, ordered, O(1) lookup const roles = new Map([ ['alice', 'admin'], ['bob', 'editor'], ]); roles.get('alice'); // 'admin' roles.has('bob'); // true roles.set('carol', 'viewer'); // Set — unique values, O(1) has() const tags = new Set(['js','css','js']); // Set {'js', 'css'} ← deduped! // Deduplicate array in one line const unique = [...new Set(arr)];
What you'll learn
5 real-world scenarios
Map basics
Any key type, insertion order
new Map()set()get()has()sizeMap iteration
Loop, count, transform
forEach()keys()values()entries()Set basics
Unique values, fast lookup
new Set()add()has()delete()Set operations
Union, intersection, difference
union()intersection()difference()WeakMap & WeakSet
GC-safe caching & private data
WeakMapWeakSetprivate dataQuick reference
All Map & Set methods
Map
Set
Set operations (ES2025)
WeakMap & WeakSet