Skip to content

Instantly share code, notes, and snippets.

@Polkovn1k
Created March 20, 2023 19:57
Show Gist options
  • Save Polkovn1k/4e349ff99f1e0d739b6fb9fed60c1927 to your computer and use it in GitHub Desktop.
Save Polkovn1k/4e349ff99f1e0d739b6fb9fed60c1927 to your computer and use it in GitHub Desktop.
Conditionally add to object (JS)
const trueCondition = true;
const someObj = {
...trueCondition && { birds: "tweet" },
...(trueCondition && { dogs: "woof" }),
};
// someObj === { birds: 'tweet', dogs: "woof" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment