Skip to content

Instantly share code, notes, and snippets.

@johnborges
Created June 5, 2021 12:42
Show Gist options
  • 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