The Spread Operator and Arrays

In this lesson, you will learn how to use the spread operator with arrays.

Creating a copy

Three dots (...) define the spread operator. It can be used on an array to take every element of the array, create a copy of each element, and return the copied variables. If you spread an array of three elements, you will receive a copy of the ten elements positioned one after the other. In the following example, line 1 is the original array. The following line, line 2, does the copy with the spread operator.

Line 4 demonstrates that they are copies and do not point to the same value.

Get hands-on with 1200+ tech skills courses.