lodash.without 删除具有特定字段的对象的函数

lodash.without function that remove object with specific field

我熟悉_.withoutfunction

这将从数组中删除特定值:

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

是否有内置/lodash 函数(或者 - 我怎样才能实现一个有效的函数)它不删除特定值而是删除具有指定字段值的 var/

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

您可以使用 _.filter:

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

或者,没有新的箭头符号:

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