How to Use the Spread Operator (…) in JavaScript

The spread operator is a useful and quick syntax for adding items to arrays, combining arrays or objects, and spreading an array out into a function’s arguments.

Dr. Derek Austin 🥳
Coding at Dawn

--

Photo by Ethan Robertson on Unsplash

What is the spread operator?

In JavaScript, spread syntax refers to the use of an ellipsis of three dots () to expand an iterable object into the list of arguments.

“When ...arr is used in the function call, it ‘expands’ an iterable object arr into the list of arguments.” — JavaScript.info

The spread operator was added to JavaScript in ES6 (ES2015), just like the rest parameters, which have the same syntax: three magic dots .

Photo by Sumner Mahaffey on Unsplash

What is ... used for?

“Spread operator to the rescue! It looks similar to rest parameters, also using ..., but does quite the opposite.” — JavaScript.info

--

--

Dr. Derek Austin 🥳
Coding at Dawn

I write about real-world programming career advice, MongoDB vs. PostgreSQL, Git, React, JavaScript, VS Code, TypeScript, and Next.js. Doctor of Physical Therapy