Created
March 20, 2023 19:57
-
-
Save Polkovn1k/4e349ff99f1e0d739b6fb9fed60c1927 to your computer and use it in GitHub Desktop.
Conditionally add to object (JS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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