gpt4 book ai didi

javascript - Lodash 过滤并省略

转载 作者:搜寻专家 更新时间:2023-11-01 00:17:27 24 4
gpt4 key购买 nike

有没有一种方法可以过滤数组,但使用 lodash 省略某些键:值?例如:

var people = [{
_id: 0,
name: 'Joe',
type: 1
}, {
_id: 1,
name: 'James',
type: 2
}, {
_id: 2,
name: 'Mary',
type: 0
}, {
_id: 3,
name: 'Clark',
type: 0
}];

var people_with_type_0 = _.filter(people, { 'type': 0 });

// so people_with_type_0 now contains the following
var people_with_type_0 = [{
_id: 2,
name: 'Mary',
type: 0
}, {
_id: 3,
name: 'Clark',
type: 0
}];

上面很精彩,但我想省略类型?

最佳答案

_.map(_.filter(people,{type : 0}),_.partial(_.omit,_,'type'))

关于javascript - Lodash 过滤并省略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35292229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com