Warunkowo dodaj elementy do obiektu

const condition = true
const obj = Object.assign({}, condition ? {
  b: 5
} : null)
console.log(obj)
Prickly Partridge