Created
January 12, 2022 14:35
-
-
Save haayhappen/47e21b801114ba214e0a04a57bf8c9ca to your computer and use it in GitHub Desktop.
How to spread truthy values into an object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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