Below is a sample list of properties:
const firstProperty = this.checkSome(param) ? this.someArray[1] : null;
const secondProperty = this.anotherProperty ? this.anotherProperty.id : null;
I am looking to create an object using these properties:
myObject = {
firstProperty,
secondProperty,
};
While everything works as expected, the issue arises when myObject contains properties that are null or undefined. I want the created object to only include properties that have values and exclude any that do not. How can I achieve this in the shortest way possible? Keep in mind that there may be more than two properties, potentially up to a dozen.