JavaScript Array Spread: Combine and Copy Iterables
Quick answer
Array spread expands an iterable into individual positions in a new array. It is convenient for concatenation and shallow copying.
How it works
[...left, extra, ...right] consumes each iterable in order. Nested objects remain shared; sparse array positions are read as undefined in ordinary arrays. The same spelling expands arguments in a call, but that is a different syntactic context.
const left = [1, 2];const combined = [...left, 9, ...[3]];console.log(combined.join(","));Expected output in Node.js:
1,2,9,3The expanded values appear where spread is written.
const source = [{score: 2}];const copy = [...source];copy[0].score = 6;console.log(source[0].score, source === copy);Expected output in Node.js:
6 falseThe outer arrays differ; the inner object is shared.
Common mistakes
[left, right] creates two nested positions, not one combined sequence. Spread is not a recursive clone.
Practice
Combine two groups of scores with a separator value and inspect their originals.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Array Spread: Combine and Copy Iterables — Knowledge Check
Apply the taught concept and predict the output.
What does array spread require from its source?
What kind of copy does [...items] make for nested objects?
What happens to a hole in an ordinary array when spread into a new array?
What is the exact console output in JavaScript Array Spread: Combine and Copy Iterables example 1?
const left = [1, 2];const combined = [...left, 9, ...[3]];console.log(combined.join(","));What is the exact console output in JavaScript Array Spread: Combine and Copy Iterables example 2?
const source = [{score: 2}];const copy = [...source];copy[0].score = 6;console.log(source[0].score, source === copy);