Lodash.without function that removes an object with a specific field

I am familiar with the _.without function

This will remove certain values ​​from the array:

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

Is there a built-in function / lodash (or - how can I implement an effective one) that removes not a specific value, but var with the given value of the / field

_.without([ { number: 1}, {number: 2} ], 1)
// -> [ {number: 2} ]
+4
source share
1 answer

You can use _.filter:

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

or, without a new arrow:

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

Source: https://habr.com/ru/post/1613264/


All Articles