Spread (...)

Expands an iterable or object into individual elements, arguments, or properties.

Since ES2015 (ES6) Spec ↗

Syntax

[...iterable]
fn(...args)
{ ...obj }

Examples

const a = [1, 2];
const b = [...a, 3, 4];
console.log(b);
Output
[ 1, 2, 3, 4 ]
const nums = [5, 1, 9];
console.log(Math.max(...nums));
Output
9
const base = { a: 1 };
const merged = { ...base, b: 2 };
console.log(merged);
Output
{ a: 1, b: 2 }

Notes

- Array/argument spread works on any iterable; object spread copies own enumerable properties. - Spread performs a shallow copy. - Object spread is ES2018; array and call spread are ES2015.

Browser & runtime support

EnvironmentSince version
chrome 46
firefox 16
safari 8
edge 12
node 5.0

See also