Skip to content

Instantly share code, notes, and snippets.

@johnborges
Created June 5, 2021 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnborges/731bc3fbd442f225e2e9d7f77da27441 to your computer and use it in GitHub Desktop.
Save johnborges/731bc3fbd442f225e2e9d7f77da27441 to your computer and use it in GitHub Desktop.
The shortest way to conditionally insert properties into an object literal.
const obj = {
...condition && { prop: value },
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment