Skip to content

Instantly share code, notes, and snippets.

@cristinafsanz
Forked from rubnvp/spread-operator.js
Created November 12, 2020 11:14
Show Gist options
  • Select an option

  • Save cristinafsanz/8953321bfc450f8792f97c551fcd1278 to your computer and use it in GitHub Desktop.

Select an option

Save cristinafsanz/8953321bfc450f8792f97c551fcd1278 to your computer and use it in GitHub Desktop.
JavaScript spread operator to conditionally add keys to objects or elements to arrays
const user = {
name: 'John',
...isAdmin && {adminGroup: 'super-admin'},
};
const options = [
'fruits',
...hasFlowers ? ['flowers'] : [],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment