groupBy
function groupBy<T, K extends any>(arr: T[], keyFn: (item: T) => K)
Groups the elements of an array based based on a given criteria function.
const grouped = Utils.groupBy(['one', 'two', 'three'], str => str.length); // group by the length of the strings
// {3: ['one', 'two'], 5: ['three']} (one and two have 3 characters, three has 5 characters)
Parameter
Type
Optional
Description
arr
T[]
❌
The array to goup
keyFn
(item: T) => K
❌
The function that returns the key to group by
Last updated