Use Spread Syntax (...) instead of '.apply'

The spread syntax (...) allows iterables like array expressions to be expanded in place where arguments are expected. It can used in place of .apply. For example Math.min.apply(Math, args) can be replaced with Math.min(...args).

Learn More: Function.prototype.apply() (MDN)

Only .apply calls are converted to the spread syntax ....

In non-strict mode, a null or undefined context is replaced with the global object. If the function uses this in non-strict mode, please ensure that it does not rely on properties of the global object.

Original Code

Changes

1const items = [1, 2, 3];1const items = [1, 2, 3];
2const container = [];2const container = [];
3container.push.apply(container, items);3container.push(...items);
11const items = [1, 2, 3];
22const container = [];
3container.push.apply(container, items);
3container.push(...items);

Transformed Code

const items = [1, 2, 3];
const container = [];
container.push(...items);

Explore More