js set value in object only if defined

JavaScript
const value = getValue()
const destination = {
  ...(value ? { value } : {})
}

Source

Also in JavaScript: