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} ]
unset() method is used to remove the property at the path of the object. If the property is removed then it returns True value otherwise, it returns False.
remove() Method. The _. remove() method is used to remove all elements from the array that predicate returns True and returns the removed elements.
The _. get() function is an inbuilt function in the Underscore. js library of JavaScript which is used to get the value at the path of object. If the resolved value is undefined, the defaultValue is returned in its place. Syntax: _.get(object, path, [defaultValue])
The Lodash _. noop() method is used to return “undefined” irrespective of the arguments passed to it. Syntax: _.noop() Parameters: This method can take optional parameters of any type. Returns: This method returns undefined.
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 })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With