最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - lodash.without function that remove object with specific field - Stack Overflow

programmeradmin6浏览0评论

I'm familiar with _.without function

This will remove specific values from an array:

_.without([1, 2, 1, 3], 1, 2);
// → [3]

Is there a built-in / lodash function (or - how can I implement an efficient one) that remove not a specific value but a var with a specified field value/

_.without([ { number: 1}, {number: 2} ], 1)
// -> [ {number: 2} ]

I'm familiar with _.without function

This will remove specific values from an array:

_.without([1, 2, 1, 3], 1, 2);
// → [3]

Is there a built-in / lodash function (or - how can I implement an efficient one) that remove not a specific value but a var with a specified field value/

_.without([ { number: 1}, {number: 2} ], 1)
// -> [ {number: 2} ]
Share Improve this question edited Nov 13, 2015 at 3:19 royhowie 11.2k14 gold badges53 silver badges67 bronze badges asked Oct 26, 2015 at 22:01 ShikloshiShikloshi 3,8119 gold badges39 silver badges60 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 16

You can use _.filter:

_.filter([ { number: 1}, {number: 2} ], (o) => o.number != 1)

or, without the new arrow notation:

_.filter([ { number: 1}, {number: 2} ], function (o) { return o.number != 1 })
发布评论

评论列表(0)

  1. 暂无评论