Spread operator
With ES6 comes the spread operator that is helpful in many ways.The spread operator spreads an array into individual entries
Copying arrays
Pre ES6
var arr = [1,2,3];
var copy = arr.slice();
ES6
var arr = [1,2,3];
var copy = [...arr]
Placing an array in a specific index within another array
Pre ES6
var arr1 = [1,2,3,4,5];
var arr2 = [21,22];
var result = arr1.slice( 0, 2 ).concat( arr2 ).concat( arr1.slice( 2 ));
ES6
var result = [1,2,...arr,3,4];
Concat arrays
Pre ES6
var arr3 = arr1.concat(arr2);
ES6
var arr3 = [...arr1,...arr2];
Call methods that have several parameters
ES6
function a(param1,param2,param3) {
}
var arr = [param1,param2,param3];
a(...arr);