Skip to content

Instantly share code, notes, and snippets.

@rubnvp
Created November 12, 2020 11:11
Show Gist options
  • Select an option

  • Save rubnvp/34670e30c29bcd664c83f43f6dc82a52 to your computer and use it in GitHub Desktop.

Select an option

Save rubnvp/34670e30c29bcd664c83f43f6dc82a52 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