delete from array of objects lodash code example

Example 1: lodash delete object property

// Block list
// Remove the values you don't want
var result = _.omit(credentials, ['age']);

// Allow list
// Only allow certain values
var result = _.pick(credentials, ['fname', 'lname']);

Example 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"]

Example 3: remove element from array lodash

var arr = [1, 2, 3, 3, 4, 5];
_.remove(arr, function(e) {
    return e === 3;
});
console.log(arr);

Example 4: remove empty object from array lodash

var myArrayFiltered = myArray.filter((ele) => {
  return ele.constructor === Object && Object.keys(ele).length > 0
});