Skip to content

groupBy

groupBy<T>(params): GroupByResult<T>

Defined in: arrays/group-by/index.ts:22

Groups array elements by a specified property value.

T

GroupByParams<T>

The parameters object

GroupByResult<T>

An object where keys are group values and values are arrays of matching items

groupBy({ array: [{ role: "admin", name: "Alice" }, { role: "user", name: "Bob" }], key: "role" });
// => { admin: [{ role: "admin", name: "Alice" }], user: [{ role: "user", name: "Bob" }] }

categorize, bucket, cluster, group array

Error if array is not an array

Error if key is undefined or null