remove undefined from array javascript lodash code example
Example 1: lodash remove undefined values from array
var colors = ["red",undefined,"","blue",null,"crap"];
var cleanColors=_.without(colors,undefined,null,"","crap");
Example 2: lodash remove undefined values from object
var person = {"name":"bill","age":21,"sex":undefined,"height":"crap"};
var cleanPerson = _.pickBy(person, function(value, key) {
return !(value === undefined || value === "crap");
});
Example 3: lodash remove element from list
var colors = ["red","blue","green","green"];
var greens = _.remove(colors, function(c) {
return (c === "green");
});