1var colors = ["red",undefined,"","blue",null,"crap"];
2// remove undefined, null, "" and any other crap
3var cleanColors=_.without(colors,undefined,null,"","crap");
4//cleanColors is now ["red","blue"];
1var colors = ["red","blue","green","green"];
2var greens = _.remove(colors, function(c) {
3 return (c === "green"); //remove if color is green
4});
5//colors is now ["red","blue"]
6//greens is now ["green","green"]
1var arr = [1, 2, 3, 3, 4, 5];
2_.remove(arr, function(e) {
3 return e === 3;
4});
5console.log(arr);
1var a = [
2 {id: 1, name: 'A'},
3 {id: 2, name: 'B'},
4 {id: 3, name: 'C'},
5 {id: 4, name: 'D'}
6];
7var removeItem = [1,2];
8removeItem.forEach(function(id){
9 var itemIndex = a.findIndex(i => i.id == id);
10 a.splice(itemIndex,1);
11});
12console.log(a);
1var array = [1, 2, 3, 4];var evens = _.remove(array, function(n) { return n % 2 === 0;});console.log(array);// => [1, 3]console.log(evens);// => [2, 4]