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

object methods · keys · values · entries

LambdaVSThe Mutator
Lambda saysObject.keys, values, and entries turn an object into iterable arrays.

Object.keys(obj) returns key names, Object.values(obj) the values, and Object.entries(obj) an array of [key, value] pairs. They let you loop objects with array methods (for...of, map) and convert back with Object.fromEntries.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleLoop an object with Object.entries and build a "k=v" string for each pair.

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 o={a:1,b:2,c:3};
document.getElementById('o').textContent=Object.entries(o).map(([k,v])=>k+'='+v).join(' ');</script></body></html>
▶ Open the interactive comic issue
‹ Objects · Key · Value PairsObject Methods · Assign · Freeze · Seal ›