Thuta Learning
AdvancedProgrammingbeginner

Spread / Rest

Relax. We'll talk through this in plain words — no textbook voice.

The Spread (...) operator expands an array or object into its individual elements/properties.

The Rest (...) operator collects multiple elements into a single array.

javascript
// Spread operator
const arr1 = [1, 2, 3];
const arr2 = [...arr1, 4, 5]; // [1, 2, 3, 4, 5]
console.log(arr2);

// Rest operator
function sum(...numbers) {
  return numbers.reduce((total, num) => total + num, 0);
}
console.log(sum(1, 2, 3, 4)); // 10
You should see
[ 1, 2, 3, 4, 5 ] 10
Spread / Rest | Thuta Learning