Skip to content

Instantly share code, notes, and snippets.

@osorionicolas
Created March 2, 2022 07:25
Show Gist options
  • Select an option

  • Save osorionicolas/f30771133f79aaea56844076d27a3d8a to your computer and use it in GitHub Desktop.

Select an option

Save osorionicolas/f30771133f79aaea56844076d27a3d8a to your computer and use it in GitHub Desktop.
Conditionally add properties to an Object
const obj = {
a: 1,
...(true && { b: 5 }),
...(false && { c: 10 }),
};
obj; // output: { a: 1, b: 5 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment