loading...

re: 5 Uses for the Spread Operator VIEW POST

FULL DISCUSSION
 

Missing my favourite use, which is to conditionally and declaratively add keys to objects, which isn't possible otherwise.

const obj = {
  a: 3,
  ...condition === true ? { b: 4 } : {},
}

Same for arrays

const plugins = [
  new BasicPlugin(),
  ...env === 'production' ? [new ProductionPlugin()] : [],
];
Code of Conduct Report abuse