Spread Operator

... Syntax

Lesson 83
+30 XP
Step 1 of 5

The Spread Operator (...)

The spread operator (...) allows you to "spread out" the elements of an array or object into individual items.

Key Concept: Think of it like unpacking a box - you take everything inside and lay it out separately.

Basic Syntax:

// Spread an array
let numbers = [1, 2, 3];
let moreNumbers = [...numbers, 4, 5];
// [1, 2, 3, 4, 5]

// Spread an object
let person = { name: 'Alice', age: 25 };
let employee = { ...person, job: 'Developer' };
// { name: 'Alice', age: 25, job: 'Developer' }

Why Use the Spread Operator?

  • Copy arrays and objects without mutating the original
  • Combine multiple arrays or objects
  • Pass array elements as function arguments
  • Clone data structures easily