“Lodash remova valores indefinidos do objeto” Respostas de código

Propriedade do objeto Lodash Excluir

// 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']);
Courageous Cicada

Lodash Remova valores indefinidos da matriz

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"];
Grepper

Lodash remova valores indefinidos do objeto

var person = {"name":"bill","age":21,"sex":undefined,"height":"crap"};
//remove undefined properties or other crap
var cleanPerson = _.pickBy(person, function(value, key) {
  return !(value === undefined || value === "crap");
});
//cleanPerson is now { "name": "bill","age": 21}
Grepper

Respostas semelhantes a “Lodash remova valores indefinidos do objeto”

Perguntas semelhantes a “Lodash remova valores indefinidos do objeto”

Mais respostas relacionadas para “Lodash remova valores indefinidos do objeto” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código