Answers for "lodash remove not in array"

2

lodash remove undefined values from array

var colors = ["red",undefined,"","blue",null,"crap"];
// remove undefined, null, "" and any other crap
var cleanColors=_.without(colors,undefined,null,"","crap");
//cleanColors is now ["red","blue"];
Posted by: Guest on November-06-2019
2

lodash remove element from list

var colors = ["red","blue","green","green"];
var greens = _.remove(colors, function(c) {
    return (c === "green"); //remove if color is green
});
//colors is now ["red","blue"]
//greens is now ["green","green"]
Posted by: Guest on November-06-2019
0

remove element from array lodash

var arr = [1, 2, 3, 3, 4, 5];
_.remove(arr, function(e) {
    return e === 3;
});
console.log(arr);
Posted by: Guest on May-15-2020
0

lodash remove not in array

var a = [
  {id: 1, name: 'A'},
  {id: 2, name: 'B'},
  {id: 3,  name: 'C'},
  {id: 4, name: 'D'}
];
var removeItem = [1,2];
removeItem.forEach(function(id){
   var itemIndex = a.findIndex(i => i.id == id);
   a.splice(itemIndex,1);
});
console.log(a);
Posted by: Guest on August-12-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language