JavaScript opcional Adicionar tecla de objeto

const gender = 'male'
const data = {
  first_name: 'Joe',
  last_name: 'Doe',
  ...(gender && {gender})
}
console.log(data)
// {
//   first_name: 'Joe',
//   last_name: 'Doe'
//   gender: 'male'
// }
Stupid Shark