JS удалить неопределенную из объекта
Object.keys(obj).forEach(key => obj[key] === undefined && delete obj[key])
Thoughtful Tarantula
Object.keys(obj).forEach(key => obj[key] === undefined && delete obj[key])
const obj = {
a: 1,
b: undefined
}
// pure functional approach without side-effects
const newObject = Object.keys(obj).reduce((acc, key) => {
const _acc = acc;
if (obj[key] !== undefined) _acc[key] = obj[key];
return _acc;
}, {})
console.log(newObject)
// Object {a: 1}