-
-
Save cristinafsanz/8953321bfc450f8792f97c551fcd1278 to your computer and use it in GitHub Desktop.
JavaScript spread operator to conditionally add keys to objects or elements to arrays
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 user = { | |
| name: 'John', | |
| ...isAdmin && {adminGroup: 'super-admin'}, | |
| }; | |
| const options = [ | |
| 'fruits', | |
| ...hasFlowers ? ['flowers'] : [], | |
| ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment