async homeApi(_source: any, _args: any) {
const body = {
door: _args.door,
window: _args.window
};
}
I have a typescript code like above where I create a JSON Object called body using door and window arguments.
Typically the body should be:
{
door: 3,
window: 4
}
What I want is if _args.door is empty/blank, the body should be
{window: 4}
It should not be:
{
door: '',
window: 4
}
door: _args.doornot already do what you want? If it's undefined, it'll stay undefined. It won't just magically conjure a value out of nowhere.for...inanddeletethe properties you want according to that condition (btw,undefinedis not"").