Free JavaScript reference · Python timeline
JavaScript ES2024: Group records and expose promise controls
Object.groupBy and Map.groupBy aggregate data, while Promise.withResolvers packages a promise with its settlement functions.
Edition 15 · Published · Editorial review October 26, 2026
Standardized in ES2024 · Built-in method
Object.groupBy() and Map.groupBy()
Grouping collects items under keys chosen by a callback. Object.groupBy is convenient for string or symbol keys and returns a null-prototype object. Map.groupBy supports general keys such as object identities.
Groups contain references to the original items, not deep copies. A callback that returns a fresh object for every item creates separate identity-based groups in Map.groupBy even if those objects look alike.
The example groups small records by a named category and prints a count. This is aggregation, not validation: a missing or misspelled category needs its own policy.
Worked example
Uses ES2024 features · Script
const rows = [{kind: "book", id: 1}, {kind: "pen", id: 2}, {kind: "book", id: 3}]; const groups = Object.groupBy(rows, row => row.kind); console.log(groups.book.length); console.log(Object.getPrototypeOf(groups) === null);
Expected output
2
true
Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.
Common mistake
A null-prototype grouped object has no inherited hasOwnProperty method. Use Object.hasOwn, and remember that the rows themselves remain shared.
Try it yourself
Change an original row after grouping. Does the object in the group reflect the change?
Read more: ES2024 specification · MDN explanation and compatibility
Standardized in ES2024 · Built-in async API
Promise.withResolvers() exposes settlement functions
withResolvers returns a promise together with its resolve and reject functions. It is useful when adapting a callback or an event boundary where settlement happens outside the promise-construction expression.
The functions do not remove the need for lifecycle rules. A settled promise cannot be settled again, and exposed controls can make ownership harder to follow. Prefer an async function when it already describes the work clearly.
The example resolves once and observes the resulting value. Calling reject afterward would not change the settled result.
Worked example
Uses ES2024 features · Script
const {promise, resolve, reject} = Promise.withResolvers(); const finished = promise.then(value => console.log(value)); resolve("ready");
Expected output
ready
Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.
Common mistake
Exposing resolve does not implement cancellation, timeouts, or cleanup. Define who is allowed to settle the operation.
Try it yourself
Call resolve twice with different strings and predict the single observed result.
Read more: ES2024 specification · MDN explanation and compatibility
Recap
Object.groupBy and Map.groupBy aggregate data, while Promise.withResolvers packages a promise with its settlement functions. Check the engines your project supports before adopting new syntax or built-ins.
Read the ES2024 specification →