Skip to content

Function.groupByToMap

github-actions[bot] edited this page Jun 2, 2026 · 21 revisions

umt / groupByToMap

Function: groupByToMap()

groupByToMap<T, K>(array, iteratee): Map<K, T[]>

Defined in: Map/groupByToMap.ts:12

Groups elements of an array into a Map based on a given iteratee function. Unlike groupBy which returns Record<K, T[]>, this preserves insertion order and allows any key type (including objects and symbols).

Type Parameters

T

T

K

K

Parameters

array

T[]

Array to group

iteratee

(value, index, array) => K

Function to determine the group key for each element

Returns

Map<K, T[]>

Map with grouped elements keyed by the iteratee result

Example

groupByToMap([6.1, 4.2, 6.3], Math.floor); // Map { 6 => [6.1, 6.3], 4 => [4.2] }
groupByToMap(["one", "two", "three"], (str) => str.length); // Map { 3 => ['one', 'two'], 5 => ['three'] }

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally