Spread


Description

The apply function lets you pretend like you are passing in arguments to a function, when you're passing an array instead. But the syntax is kind of funky:

function writeArguments() {
  for (var i = 0; i < arguments.length; ++i) {
    console.log(arguments[i]);
  }
}

var arr = [1,2,3]

writeArguments.apply(undefined, arr); // ES5 style

Spread lets you pass in arguments in a much easier manner:

writeArguments(...arr); // new ES6 style

There are a lot of variations of this where it may be helpful - see the MDN page for a lot of useful ideas:

Reference

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax