Standard built-ins

Map.groupBy()

Try the free JavaScript compiler

Group iterable values by callback-produced keys. The callback receives item and index; each group is an array containing original values, not deep copies.

Formal Syntax & Structure

javascript syntaxjavascript
Map.groupBy(items, callback)

Parameters & Attributes

NameTypeDescription
itemsIterableValues to group.
callbackFunctionReceives item and index; returns key.

Return Value

Map

Keys mapped to group arrays.

Working Example

Example Snippetjavascript
const m=Map.groupBy([1,2,3],n=>n%2);console.log(JSON.stringify(m.get(1)));
JavaScript Reference