← Back to release summary

Array grouping

Category
JavaScript
Type
Chromium catches up
Status
Enabled by default (Chrome 117)
Intent stage
Prepare to ship

Summary

Adds news Object.groupBy(iterable, groupCallback) and Map.groupBy(iterable, groupCallback) to perform a grouping or bucketing operation. The Object method returns a plain object, where the groups are property keys. The Map method returns a Map, where the keys can be arbitrary values.

Motivation

From the proposal explainer: Array grouping is an extremely common operation, best exemplified by SQL's GROUP BY clause and MapReduce programming (which is better thought of map-group-reduce). The ability to combine like data into groups allows developers to compute higher order datasets, like the average age of a cohort or daily LCP values for a webpage.

Standards & signals

Explainers: https://github.com/tc39/proposal-array-grouping/blob/main/README.md

View on chromestatus.com