DEV Community

Discussion on: 5 Uses for the Spread Operator

Collapse
 
j3m5 profile image
J3m5

You can also use it to conditionally add properties to objects.

const obj = {
  a:1,
  ...true && {b:2},
  ...false && {c:3}
}

// {a:1,b:2}