groupBy
groupBy<
T>(params):GroupByResult<T>
Defined in: arrays/group-by/index.ts:22
Groups array elements by a specified property value.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”params
Section titled “params”GroupByParams<T>
The parameters object
Returns
Section titled “Returns”GroupByResult<T>
An object where keys are group values and values are arrays of matching items
Example
Section titled “Example”groupBy({ array: [{ role: "admin", name: "Alice" }, { role: "user", name: "Bob" }], key: "role" });// => { admin: [{ role: "admin", name: "Alice" }], user: [{ role: "user", name: "Bob" }] }Keywords
Section titled “Keywords”categorize, bucket, cluster, group array
Throws
Section titled “Throws”Error if array is not an array
Throws
Section titled “Throws”Error if key is undefined or null