主题
group
将数组项分组
基本用法
给定一组项目,group
将会构建一个对象,其中每个键是属于该组的项目数组。通常,这对于分类数组很有用。
ts
import { group } from 'radash'
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] }