Looking for a shorthand method to assign properties to an object ONLY when the assigning variable is defined.
Current Code:
let count = {}, one = 1, two = 2, four = 4;
if (one) count.one = one;
if (two) count.two = two;
if (three) count.three = three;
if (four) count.four = four;
Result:
count = { one: 1, two: 2, four: 4 }
Normally, I would try this:
let count = { one, two, three, four }
However, it complains when three is undefined...
Is there a better method to shorthand assign only when defined?
What I cannot have:
count = { one: 1, two: 2, three: undefined, four: 4 }