I have a payload which may or may not contain a value.
const { mainValue } = payload;
This mainValue can either only be optionaA or optionB.
I am constructing another object based on this value. How can I conditionally construct the below object. Either I need newProp1 or just newProp2. Is there an ES6 way of doing it, which will be neater.
const newObj = {
propertyA: someValue,
AttributeA: {
newProp1: {
value: optionaA
},
//// i need newProp1 or newProp2 in this newObj
newProp2: {
value: optionaB
}
}
}
mainValuecould also beundefined? If so, what should the result look like in that case?