Skip to content

Instantly share code, notes, and snippets.

@haayhappen
Created January 12, 2022 14:35
Show Gist options
  • Save haayhappen/47e21b801114ba214e0a04a57bf8c9ca to your computer and use it in GitHub Desktop.
Save haayhappen/47e21b801114ba214e0a04a57bf8c9ca to your computer and use it in GitHub Desktop.
How to spread truthy values into an object
const one = 'one'
const two = null
const three = {
...(one && { one }),
...(two && { two })
}
console.log(three)
// { one: 'one' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment