← Back to Roadmap

Spread Operator (...)

Easy

In plain terms

The spread operator ... expands iterables (arrays, strings) or object properties. Use it to copy arrays/objects, merge them, or pass array elements as separate arguments.

What you need to know

  • ...iterable or ...object
  • Shallow copy
  • Expands to elements/properties

Try it yourself

Copy the code below and run it in your browser console or a code editor:

// Copy array
const arr = [1, 2, 3];
const copy = [...arr];

// Merge arrays
const merged = [...[1, 2], ...[3, 4]];  // [1, 2, 3, 4]

// Copy object
const obj = { a: 1, b: 2 };
const objCopy = { ...obj };

// Merge with override
const updated = { ...obj, b: 3 };  // { a: 1, b: 3 }

// Function args
Math.max(...[1, 5, 3]);  // 5

Learn more

Dive deeper with these trusted resources: