BeginnerCoder

Lesson 9 — Spread & rest

The ... operator

Spread (...arr) expands an array into its separate items, for example inside a new array literal. You can spread several arrays and mix in single values. Rest looks the same but works the other way: ...args in a parameter list collects leftover arguments into an array.

const nums = [2, 3];
const more = [1, ...nums, 4]; // [1, 2, 3, 4]

Why it matters: spreading is the standard way to copy and combine arrays without changing the originals.

Want it another way?
Task

Merge both arrays into all with spread, so it logs [1, 2, 3, 4].

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.