Created
March 2, 2022 07:25
-
-
Save osorionicolas/f30771133f79aaea56844076d27a3d8a 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 obj = { | |
| a: 1, | |
| ...(true && { b: 5 }), | |
| ...(false && { c: 10 }), | |
| }; | |
| obj; // output: { a: 1, b: 5 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment