Spread to Copy Array
Fill in the Blank Easy
Question
Fill in the blank to create a copy of `original` using the spread operator.
Code
const original = [1, 2, 3];
const copy = ___;
copy.push(4);
console.log(original.length);
Hint
Spread the original array into a new array literal.
Explanation
[...original] creates a new array with all elements of original. Pushing to copy does not affect original because they are separate arrays. So original.length is still 3. This is the modern way to shallow-copy an array.
Related Resources
Related Lessons
- JavaScript Arrays
Learn about spread for copying.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.