Created
September 11, 2018 16:08
-
-
Save caryfuk/197bd148da3295aff0415975201b9de9 to your computer and use it in GitHub Desktop.
conditionally add key to an object
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 account = { | |
email, | |
password, | |
...(nickname && {nickname}), | |
} | |
// https://medium.freecodecamp.org/how-to-conditionally-build-an-object-in-javascript-with-es6-e2c49022c448 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment