Spread & Rest Operators (...) in JavaScript
From the JavaScript cheat sheet · Modern JavaScript (ES6+) · verified Jul 2026
Spread & Rest Operators (...)
Expand iterables and collect remaining elements with the ... syntax
javascript
// Spread — expand into individual elements
const arr = [1, 2, 3];
const copy = [...arr];
const merged = [...arr, 4, 5];
const clone = { ...user, age: 31 };
// Rest — collect remaining elements
const [first, ...rest] = [1, 2, 3, 4];
function sum(...nums) { return nums.reduce((a, b) => a + b); }💡 Spread (...) expands; Rest (...) collects — same syntax, opposite operations
⚡ { ...obj } and [...arr] create SHALLOW copies — nested objects are still references
📌 const { password, ...safeUser } = user is the cleanest way to remove a property immutably
🟢 Rest params (...args) replace the old "arguments" object — they give a real array
spreadrestes6