I was expecting the lodash without function to take an array of values, but instead takes multiple args. How do I pass it an array and make it work.
Example:
var bar = {
foo: ['a', 'b', 'c']
};
_.without(bar.foo, 'c', 'a'); // works;
_.without(bar.foo, ['c', 'a']); // doesn't work
My exclusion list has to be passed in as an array or variable so it would be useful to know how to use an array with the without function.
To check if multiple values exist in an array:Use the every() method to iterate over the array of values. On each iteration, use the indexOf method to check if the value is contained in the other array. If all values exist in the array, the every method will return true .
isEqual() Method. The Lodash _. isEqual() Method performs a deep comparison between two values to determine if they are equivalent. This method supports comparing arrays, array buffers, boolean, date objects, maps, numbers, objects, regex, sets, strings, symbols, and typed arrays.
Could use spread operator
var bar = {
foo: ['a', 'b', 'c']
};
var arr = ['c', 'a'];
console.log(_.without([bar.foo], ...arr) ;
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