JavaScript Spread operator - ES6

The spread operator ... takes an iterable and expands it into the individual elements. The spread operator looks identical to the rest operator but instead performs the opposite action.

const numbers = [1, 2, 3, 4];

const moreNumbers = [...numbers, 5, 6];

console.log(moreNumbers);//=> [1, 2, 3, 4, 5, 6]

This is most useful for dealing with cases like apply where you want to pass an iterable as its components. In fact, apply is no longer needed to pass an array as arguments.

const foo = function (a, b, c) {
  console.log("a:", a); //=> "a:"1, "a:"4
  console.log("b:", b); //=> "b:"2, "b:"5
  console.log("c:", c); //=> "c:"3, "c:"6
}

const bar = [1, 2, 3];

foo(...bar);

const baz = [5,6];

foo(4, ...baz);

JavaScript - ES6