Spread operator ...

// Previously when you needed an unknown number of parameters, you would have used special variable called arguments. // ES5 function populateBucket() { var bucket = []; for (var itemCounter = 0; itemCounter < arguments.length; itemCounter++) { bucket.push(arguments[itemCounter]); } } // ES6 function populateBucket(...items) { var bucket = []; for(item of items) { bucket.push(item); } } // You can also use it to merge arrays var a = [1,2,3], b = [4,5,6], merged = []; // What used to be the following for merging arrays merged = a.concat(b); // Can now be written as merged = [...a, ...b];

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.