Posts Conditionally add key/value to object
Post
Cancel

Conditionally add key/value to object

Neat little trick to conditionally add a key and value to an object:

1
2
const someBoolean = true;
...(someBoolean && {key: "value"})
This post is licensed under CC BY 4.0 by the author.