Skip to content

spread syntax (...)

In JavaScript, spread syntax (...) is syntax that expands an array, a string, or another iterable into separate elements or arguments, or copies an object’s own enumerable properties into a new object.

Spread works in three places: array literals, function calls, and object literals. Array literals and function calls need an iterable, such as an Array, a Set, or a string. Object literals accept any value and copy its own enumerable properties into the new object. The same ... token also appears in rest parameters and in the rest elements of destructuring, where it collects values instead of expanding them.

JavaScript Spread Syntax Forms

Spread syntax has one form for each place it can appear:

Language: JavaScript Syntax
[...<iterable>]
<function>(...<iterable>)
{ ...<object> }

Each form can sit next to other elements, arguments, or properties, and a single literal or call can spread more than one value.

JavaScript Spread Syntax Examples

Say a weather app stores daily readings in an array, but Math.max() takes its numbers as separate arguments. Spreading the array passes each reading on its own:

Language: JavaScript
> const readings = [21.5, 19, 24.25];
undefined

> Math.max(...readings)
24.25

> Math.max(readings)
NaN

> [...readings, 22]
[ 21.5, 19, 24.25, 22 ]

Without the spread, Math.max() receives one array argument and returns NaN. In the array literal, spread copies the readings into a new array and appends one more value.

A settings screen can merge a user’s saved choices over a set of defaults. Object spread copies both objects into a new one, and a later property wins over an earlier one with the same key:

Language: JavaScript
> const defaults = { theme: "light", fontSize: 14 };
undefined
> const saved = { fontSize: 18 };
undefined

> ({ ...defaults, ...saved })
{ theme: 'light', fontSize: 18 }

> defaults
{ theme: 'light', fontSize: 14 }

The result is a new object, so defaults keeps its original values.

JavaScript Spread Syntax Gotchas

Spread syntax has limits that surprise people reading code that uses it:

  • Spread makes a shallow copy, so nested objects and arrays are shared between the copy and the original.
  • Spreading a plain object or null into an array literal or a function call throws a TypeError, while object literals skip null and undefined.
  • Object spread copies only own enumerable properties and drops the prototype, so a copy of a class instance is a plain object.
  • Spreading a very large array into a function call can exceed the engine’s limit on arguments and throw an error.

A deep copy of nested data takes structuredClone() instead of spread.

JavaScript Spread Syntax Use Cases

Common uses of spread syntax include:

  • Copying an array or an object before changing the copy
  • Merging default settings with user overrides into a new object
  • Passing the elements of an array as separate arguments to a function
  • Combining several arrays, or turning a string or a Set into an array
  • Updating one property of a state object while keeping the others

Code that treats state as immutable, such as a reducer, relies on these patterns.

A developer places a cube on a conveyor at the end of a clay rack of numbered slots while a claw lifts the middle cube out, with SHIFT, PUSH, SORT and SLICE consoles.

Course

JavaScript Arrays for Pythonistas

Port a support team's on-call rota script from Python to JavaScript, and learn how arrays replace Python's lists and tuples, from indexing and slicing to editing, searching, and sorting.

basics js py

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 12, 2026