JavaScript Opsional Add Object Key

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