Skip to content

group

Categorize elements from an array into distinct groups

133 bytes
since v12.1.0

Usage

Given an array of items, group will build up an object where each key is an array of the items that belong in that group.

import * as _ from 'radashi'
const fish = [
{
name: 'Marlin',
source: 'ocean',
},
{
name: 'Bass',
source: 'lake',
},
{
name: 'Trout',
source: 'lake',
},
]
const fishBySource = _.group(fish, f => f.source) // => { ocean: [marlin], lake: [bass, trout] }