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

map · ordered key-value store

LambdaVSThe Mutator
Lambda saysMap is a key–value store where keys can be any type and order is preserved.

Unlike plain objects, a Map accepts any key type (objects, functions, not just strings), keeps insertion order, has a real .size, and is directly iterable. Use set, get, has, delete. Reach for Map when keys aren't strings or you need frequent add/remove and size.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleUse a Map with an object as a key, then iterate its entries.

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 m=new Map(); const key={}; m.set(key,'obj-keyed'); m.set('s',1);
document.getElementById('o').textContent='size='+m.size+' val='+m.get(key);</script></body></html>
▶ Open the interactive comic issue
‹ Symbols · Unique KeysSet · Unique Values ›