From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Learn about the spread operator

Learn about the spread operator

- Another really helpful syntax that ES6 provides us with comes into view when working with objects and arrays. And this is something called the spread operator. When working with objects or arrays in JavaScript, it happens quite often that we want to combine two or more arrays or objects into one. Now, before ES6, if you wanted to do this, you sort of had to either loop through all the properties in both objects and set those properties on another object, or you could use the function called object.assign, which took care of all that for you. But personally, I always found that code like this was a bit of an eyesore. So what ES6 has provided us with in order to make these kinds of operations easier is something called the spread operator. And it looks something like this. If we wanted to combine our two objects, like we did before, we could simply use the spread operator, which is three dots before the object name, to sort of spread the properties and values of each object into the…

Contents