Created
May 30, 2019 11:49
-
-
Save jbutko/6c670c0270bf504aaab1ba94fe75f047 to your computer and use it in GitHub Desktop.
The shortest way to conditional insert properties into an object literal
This file contains hidden or 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 obj = { | |
...condition && { prop: value }, | |
}; | |
// via From https://dev.to/jfet97/the-shortest-way-to-conditional-insert-properties-into-an-object-literal-4ag7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment