Lodash group by multiple properties if property value is true

前端 未结 8 1903
执笔经年
执笔经年 2020-12-10 02:20

I have an array of vehicles that need to be grouped by make and model, only if the \'selected\' property is true. The resulting object should contain properties for make mod

8条回答
  •  天涯浪人
    2020-12-10 02:43

    const result = _.chain(vehicles)
    .filter('selected')
    .groupBy('makeCode')
    .mapValues(values => _.chain(values)
        .groupBy('modelCode')
        .mapValues(_.size)
        .value()
    )
    .value()

提交回复
热议问题