Skip to content

Instantly share code, notes, and snippets.

Created Jun 1, 2018
What would you like to do?
Spread Operator in ES6
let doWork = function(x, y, z){
return x + y + z;
//using the ... syntax on an array we are able to pass in the params as follows:
nums = [1, 2, 3]
let result = doWork(...nums)
//which is the equivelent as
let other_result = doWork(1,2,3);
//spread can also be used to build arrays
let a = [1,3,5]
let b = [2,3, ...a,4]
console.log(b); //b is equal to [2,3,1,3,5,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment