xxxxxxxxxx
const obj = {
a: 1,
b: undefined
}
// removing undefined values if it presents in the obj
const obj1 = JSON.parse(JSON.stringify(obj));
xxxxxxxxxx
var obj = { a: 1, b: undefined, c: 3 }
console.log(JSON.parse(JSON.stringify(obj)));
Output: {a: 1, c: 3}
xxxxxxxxxx
Object.keys(obj).forEach(key => obj[key] === undefined && delete obj[key])
xxxxxxxxxx
Object.keys(obj).forEach(key => obj[key] === undefined ? delete obj[key] : {});