Skip to content

Instantly share code, notes, and snippets.

@aderaaij
Last active July 25, 2018 09:27
Show Gist options
  • Save aderaaij/13f737d5630db2e1cf46a9fbe0fccb9f to your computer and use it in GitHub Desktop.
Save aderaaij/13f737d5630db2e1cf46a9fbe0fccb9f to your computer and use it in GitHub Desktop.

Revisions

  1. aderaaij revised this gist Nov 15, 2017. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion es6-spread-operator.js
    Original file line number Diff line number Diff line change
    @@ -6,5 +6,15 @@ const heroes = [...avengers, 'Loki', ...guardians];
    // Adding new stuff to an array just got easier too
    guardians = [...guardians, 'Mantis', 'Yondu', 'Nebula'];

    // Or simply making a copy of an array
    // Or simply making a TRUE copy of an array
    const avengersCopy = [...avengers];

    // We can also get everything out of an array in an object
    const xmen = {
    team: 'Marvel',
    leader: 'Xavier',
    members: ['Jean Grey', 'Cyclopse', 'Beast', 'Gambit', 'Rogue', 'Wolverine'],
    }

    // This creates another true copy of the Array with new values in it.
    const xMenSpecial = ['Gambit', 'Mystique', 'Magneto', ...xmen.members];
  2. aderaaij revised this gist Nov 15, 2017. 1 changed file with 9 additions and 6 deletions.
    15 changes: 9 additions & 6 deletions es6-spread-operator.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,10 @@
    const avengers = ['Thor', 'The Hulk', 'Captain America'];
    const guardians = ['Star Lord', 'Gamorra', 'Drax', 'Rocket', 'Groot'];
    // Spread out arrays in a new array and put a new value in between them
    const heroes = [...avengers, 'Loki', ...guardians];
    const avengers = ['Thor', 'The Hulk', 'Captain America'];
    let guardians = ['Star Lord', 'Gamorra', 'Drax', 'Rocket', 'Groot'];
    // Spread out arrays in a new array and put a new value in between them
    const heroes = [...avengers, 'Loki', ...guardians];

    // Adding some new values to it just got easier
    const guardiansVol2 = [...guardians, 'Mantis', 'Yondu', 'Nebula'];
    // Adding new stuff to an array just got easier too
    guardians = [...guardians, 'Mantis', 'Yondu', 'Nebula'];

    // Or simply making a copy of an array
    const avengersCopy = [...avengers];
  3. aderaaij revised this gist Nov 15, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion es6-spread-operator.js
    Original file line number Diff line number Diff line change
    @@ -3,5 +3,5 @@
    // Spread out arrays in a new array and put a new value in between them
    const heroes = [...avengers, 'Loki', ...guardians];

    // Copying an array and adding some new values to it just got easier
    // Adding some new values to it just got easier
    const guardiansVol2 = [...guardians, 'Mantis', 'Yondu', 'Nebula'];
  4. aderaaij created this gist Nov 15, 2017.
    7 changes: 7 additions & 0 deletions es6-spread-operator.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    const avengers = ['Thor', 'The Hulk', 'Captain America'];
    const guardians = ['Star Lord', 'Gamorra', 'Drax', 'Rocket', 'Groot'];
    // Spread out arrays in a new array and put a new value in between them
    const heroes = [...avengers, 'Loki', ...guardians];

    // Copying an array and adding some new values to it just got easier
    const guardiansVol2 = [...guardians, 'Mantis', 'Yondu', 'Nebula'];