Jobs
Blogs
Courses
Mentorship
Partners
For Employers
e2e logo

JavaScript Spread Operator

mac

JavaScript Spread Operator

The JavaScript spread operator (...) allows us to quickly copy all or part of an existing array or object into another array or object. 

Example

ES6 provides a new operator called spread operator that consists of three dots (...). The spread operator allows you to spread out elements of an iterable object such as an array, map, or set. For example:

In this example, the three dots ( ...) located in front of the odd array is the spread operator. The spread operator (...) unpacks the elements of the odd array.

JavaScript spread operator and array manipulation

1. Constructing array literal

     The spread operator allows you to insert another array into the initialized array when you construct an array using the literal form. See      the following example: 

2. Concatenating arrays

    Also, you can use the spread operator to concatenate two or more arrays:

3. Copying an array 

    In addition, you can copy an array instance by using the spread operator: