I am usually constructing objects that do have fields in them or do not have them based on a condition so
let data
if(something === true) {
data = {
name: 'String',
something: 'Something'
}
else {
data = {
name: 'String'
}
}
but this seems like a very "dirty way to do this" as data needs to be redefined every time + if there were more if conditions this would become quiet big chunk of code. Is there a more concise way to achieve this?