08 Spread - Gilian/001-ES6-By-Wes GitHub Wiki

Spread

Spread is a new keyword in ES6 and can combine iterables. For example you can take each letter in a string and put it an array. The keyword for spread are three dots before the iterable you want to spread.

The example takes two arrays and combines them into one with a new word in the middle. This would be nasty to achieve without spread:

// arrays
const features = ['Deep Dish', 'Perperoni'];
const special = ['Meatizza', 'Spicy Mama'];

const pizza = [...features, 'vegi', ...special];

Copy an array without pointing to the original array

// original array name is pizza
const newPizza = [...pizza];