ES6: Spread Operator
6min read
The spread syntax allows arrays, objects and array like objects (e.g. arguments object, DOM node objects) to be expanded in places where multiple arguments (for function calls) are expected. In order to use the spread operator simply write three dots “…” preceeding the expression that should get “spread”.
The Spread Operator is a sibling of the Rest Parameter which both share the same syntax. It is a great new feature and probably best observed in action.
The better apply
We can use the spread operator instead of apply to call a function and pass it an array of arguments.
ES5
ES6
Merging arrays
We can use the spread operator to merge multiple arrays.
ES5
ES6
The array can be spreaded anywhere it is necessary.
As initially stated it works not only for arrays and array-like objects but also objects itself. We can use the spread operator to create a fresh new copy of an object that inherits all the properties of the cloned object. But be aware: the spread operator is not suitable to deep clone an object as it goes only one level deep.
Copy an array
We can use it to make a frew new copy of an array without a reference.
ES5
ES6
Convert array-like objects to arrays
Sometimes it is necessary to convert an array-like object to an array, e.g. in order to use methods which are only available for arrays such as filter, map or reduce.
ES5
ES6
Trackbacks & Pingbacks
-
… [Trackback]
[…] Find More Information here to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More here to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More Information here to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More here on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More Information here to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More Info here on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Here you can find 30975 more Information to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More on on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More here to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
[…] 1127228084258779897577937057145323407796017167870434515318812876129641818497 Post navigation ← Previous PostNext Post → […]
-
… [Trackback]
[…] Information on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Here you can find 8136 additional Information to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Here you can find 78174 more Information on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Info to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More Info here on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Info on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More here to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More Info here on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More here to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Info to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Information on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More Info here on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More here on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More Info here on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More Information here on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Here you will find 9930 more Information to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Info on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More Info here to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Info on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Information to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More to that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Find More on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] There you will find 11626 additional Info on that Topic: ilearnjavascript.com/es6-spread-operator/ […]
-
… [Trackback]
[…] Read More here: ilearnjavascript.com/es6-spread-operator/ […]
Leave a Reply
Want to join the discussion?Feel free to contribute!
Buy TOEFL IELTS Online
Buy a verified TOEFL certificate without taking online exams. The TOEFL is the most common academic English test in the world
Are you looking to buy driver’s license online, buy real driver’s license online? Your search has landed you on the right page.
Getting a passport for another country has never been easier than it is today, anyone can legally buy a passport
Getting a passport for another country has never been easier than it is today