Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use lodash _ without operator with an array rather than multiple args

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.

like image 990
MonkeyBonkey Avatar asked Apr 03 '15 13:04

MonkeyBonkey


People also ask

How do you check if an array contains multiple values?

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 .

How do I compare two arrays of objects in lodash?

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.


1 Answers

Could use spread operator

var bar = {
    foo: ['a', 'b', 'c']
};

var arr = ['c', 'a'];

console.log(_.without([bar.foo], ...arr) ;
like image 132
user3462064 Avatar answered Oct 20 '22 04:10

user3462064