JavaScript ... Spread syntax Operator
Spread syntax (...) expands an array, string or object into individual elements or properties. The same syntax collects remaining items as rest parameters.
Description
Spread syntax ... expands an iterable, such as an array, string, Set or Map, into individual elements, or an object into its properties. In array literals it copies or merges arrays ([...a, ...b]); in function calls it passes array elements as separate arguments (Math.max(...nums)); in object literals it copies properties ({ ...defaults, ...options }), later ones overriding earlier ones.
The same three dots do the opposite job as rest syntax: in function parameters and destructuring patterns, they collect the remaining items into an array or object. All copies made with spread are shallow.
Spreading an object copies its own enumerable properties, including symbol-keyed ones, but not its prototype, getters as getters, or non-enumerable properties. Spreading null or undefined into an object is allowed and does nothing, which makes { ...defaults, ...options } safe when options is missing, but spreading them into an array throws a TypeError.
Properties
- Operator
...- Category
- Other
- Precedence
- 2 (1 is lowest, 18 is highest)
- Associativity
- n/a
Syntax
[...iterable]
{ ...object }
func(...args)
function f(...rest) {}Example
Browser Support
The following information will show you the current browser support for the ... operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





