Удалить пустые значения из объекта JS
Object.keys(obj).forEach((k) => (obj[k] === null || obj[k] === undefined) && delete obj[k]);
Crazy Capybara
Object.keys(obj).forEach((k) => (obj[k] === null || obj[k] === undefined) && delete obj[k]);
var test = {
test1: null,
test2: 'somestring',
test3: 3,
}
function clean(obj) {
for (var propName in obj) {
if (obj[propName] === null || obj[propName] === undefined) {
delete obj[propName];
}
}
return obj
}
console.log(test);
console.log(clean(test));