Created
March 13, 2022 16:34
-
-
Save AitorAlejandro/1923dfe582498ceb27138573d592fb96 to your computer and use it in GitHub Desktop.
Conditionally add properties to 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 condition1 = true; | |
| const condition2 = false; | |
| const person = { | |
| id: 'uuid-1234', | |
| name: 'John', | |
| ...(condition1 && { propA: 'A' }), | |
| ...(condition2 && { propB: 'B' }), | |
| }; | |
| // person --> { id: 'uuid-1234', name: 'John', propA: 'A' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment