var obj = { a: 1, b: undefined, c: 3 }
console.log(JSON.parse(JSON.stringify(obj)));
Output: {a: 1, c: 3}
Object.keys(obj).forEach(key => obj[key] === undefined && delete obj[key])
const buildAnObjectFromAQuery = query => (
{
...query.foo && { foo: query.foo },
...query.bar && { bar: query.bar },
}
);