Skip to content

Instantly share code, notes, and snippets.

@caryfuk
Created September 11, 2018 16:08
Show Gist options
  • Save caryfuk/197bd148da3295aff0415975201b9de9 to your computer and use it in GitHub Desktop.
Save caryfuk/197bd148da3295aff0415975201b9de9 to your computer and use it in GitHub Desktop.
conditionally add key to an object
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