Skip to content
Justice Tech School

Spread and Rest

Spread (...) expands an array or object into separate items. Use it to copy or merge without changing the original. Rest uses the same three dots in a parameter or destructuring list to gather the leftover items.

Spread makes a shallow copy: nested objects are still shared with the original.

Example
const a = [1, 2];
const b = [...a, 3, 4];
console.log(b);
const base = { color: "green", size: 2 };
const custom = { ...base, size: 5 };
console.log(custom);
const [head, ...tail] = [10, 20, 30];
console.log(head, tail);
console.log(Math.max(...b));

Exercise

Copy the array using spread.

const copy = [original];

Quiz Test

Is spread a deep copy?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.