Spread Operator in JavaScript

Javascript 8 min min read Updated: Mar 09, 2026 Intermediate
Spread Operator in JavaScript
Intermediate Topic 8 of 15

The Spread Operator is an ES6 feature in JavaScript that allows developers to expand or spread the elements of an array or object into individual elements. It is represented by three dots (...).

The spread operator makes it easier to work with arrays, objects, and function arguments. It helps developers write shorter and more readable code compared to traditional JavaScript methods.

What is the Spread Operator?

The spread operator expands elements from an array or properties from an object into individual values. This allows developers to copy, merge, or pass multiple values easily.

Key Point: The spread operator (...) expands iterable elements such as arrays and objects into individual values.

Example with Arrays

The spread operator can expand elements of an array.

javascript let numbers = [1, 2, 3]; console.log(...numbers);
Output

1 2 3

Copying an Array

Before ES6, copying arrays required loops or special methods. With the spread operator, arrays can be copied easily.

javascript let original = [10, 20, 30]; let copy = [...original]; console.log(copy);
Output

[10, 20, 30]

Merging Arrays

The spread operator can combine multiple arrays into a single array.

javascript let arr1 = [1, 2]; let arr2 = [3, 4]; let merged = [...arr1, ...arr2]; console.log(merged);
Output

[1, 2, 3, 4]

Key Point: Spread operator provides a simple way to merge arrays without using loops.

Using Spread Operator with Functions

The spread operator can also pass array elements as arguments to a function.

javascript function add(a, b, c){ console.log(a + b + c); } let numbers = [5, 10, 15]; add(...numbers);
Output

30

Spread Operator with Objects

The spread operator can also copy or merge objects.

javascript let user = { name: "Rahul", age: 22 }; let updatedUser = { ...user, city: "Delhi" }; console.log(updatedUser);
Output

{ name: "Rahul", age: 22, city: "Delhi" }

Advantages of the Spread Operator

  • Makes code shorter and easier to read
  • Helps copy arrays and objects easily
  • Simplifies merging of arrays and objects
  • Useful for passing multiple arguments to functions

Conclusion

The spread operator is a powerful ES6 feature that allows developers to expand arrays and objects into individual elements. It simplifies tasks such as copying arrays, merging objects, and passing function arguments.

Because of its simplicity and flexibility, the spread operator is widely used in modern JavaScript development and frameworks like React.

In the next tutorial, you will learn about the Rest Operator in JavaScript, which works similarly to the spread operator but collects multiple values into a single parameter.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators