Group an array using a grouping function into an object
an object containing arrays with an entry for each group
const { odd, even } = groupArrayBy([1, 2, 3, 4], x => x % 2 === 0 ? 'even' : 'odd')// odd === [1, 3]// even === [2, 4]
const peopleByAge = groupArrayBy([ { name: 'John', age: 20 }, { name: 'Claire', age: 20 }, { name: 'Ben', age: 23 }], person => person.age)peopleByAge === { 20: [ { name: 'John', age: 20 }, { name: 'Claire', age: 20 } ], 23: [ { name: 'Ben', age: 23 } ]}
the array to create groups from
the keys to group by. Elements which return the same key when passed to this function will be in the same group
Generated using TypeDoc
Group an array using a grouping function into an object
Returns
an object containing arrays with an entry for each group
Example
Example