js object remove undefined code example
Example 1: js remove undefined from object
Object.keys(obj).forEach(key => obj[key] === undefined && delete obj[key])
Example 2: remove undefined from object js
const buildAnObjectFromAQuery = query => (
{
...query.foo && { foo: query.foo },
...query.bar && { bar: query.bar },
}
);