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 - JavaScript Tutorial
From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext
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
-
-
-
-
-
-
-
-
(Locked)
Learning objectives1m 45s
-
(Locked)
Write functions using arrow syntax4m 22s
-
Set default values for function arguments3m 32s
-
(Locked)
Learn about the spread operator4m 11s
-
(Locked)
Use object destructuring to get object properties3m 53s
-
(Locked)
Use interpolation to insert data into strings1m 44s
-
(Locked)
Learn the import and export code in JavaScript6m 19s
-
(Locked)
-
-
-
-
-
-