Rest & Spread — Idiomatic Arrays and Objects
Collect the rest of values/props, clone and merge with spread, and avoid hidden mutations with simple patterns.
Intro
Goal: Use rest to collect extras and spread to copy or merge.
- Array/object spread
- Array rest (head/tail)
- Object rest (exclude some keys)
- Mutation vs copy

Array spread basics
[...arr] copies an array; combine arrays by spreading them in a new array.
// Array spread creates a shallow copy and merges arrays
const a = [1, 2];
const b = [3, 4];
const clone = [...a];
const merged = [...a, ...b];
console.log("a:", a);
console.log("clone:", clone);
console.log("merged:", merged);

All lessons in this course
- Array/Object Destructuring Basics
- Rest & Spread — Idiomatic Arrays and Objects