Created
June 1, 2018 21:34
-
-
Save nodlAndHodl/01cf07e51a4270315b6a68749c774188 to your computer and use it in GitHub Desktop.
Spread Operator in ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
//example | |
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