I have a list of properties like that:
const firstProperty = this.checkSome(param) ? this.someArray[1] : null;
const secondProperty = this.anotherProperty ? this.anotherProperty.id : null;
Next I want to create an object, which has those properties:
myObject = {
firstProperty,
secondProperty,
};
It works fine, the problem is myObject contains those properties, even when they are null or undefined. What I want is that if, for example, secondProperty is null, then myObject do not have such property after creation, at all. What is the shortest way to achieve that? Consider that amount of properties can be more than two, in fact, I have about a dozen.