Created
June 5, 2021 12:42
-
-
Save johnborges/731bc3fbd442f225e2e9d7f77da27441 to your computer and use it in GitHub Desktop.
The shortest way to conditionally insert properties into an object literal.
This file contains 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 obj = { | |
...condition && { prop: value }, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment