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

ES2024 · groupBy · promise.withResolvers

LambdaVSThe Mutator
Lambda saysES2024 added Object.groupBy, Promise.withResolvers, and well-formed Unicode helpers.

Object.groupBy(items, fn) buckets an array into an object keyed by the function's result — no reduce boilerplate. Promise.withResolvers() returns a promise plus its resolve/reject for cleaner external control. Plus String.isWellFormed/toWellFormed for safe Unicode. The language keeps shaving off everyday friction.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleGroup an array of people by role with Object.groupBy.

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 people=[{n:'a',role:'dev'},{n:'b',role:'art'},{n:'c',role:'dev'}];
const g=Object.groupBy ? Object.groupBy(people,p=>p.role) : {};
document.getElementById('o').textContent=JSON.stringify(g);</script></body></html>
▶ Open the interactive comic issue
‹ ES2023 · Array Find From Last · Symbol.Dispose