Skip to content

Instantly share code, notes, and snippets.

@colintoh
Last active August 29, 2015 14:07
Show Gist options
  • Save colintoh/0b54eda528941727f66b to your computer and use it in GitHub Desktop.
Save colintoh/0b54eda528941727f66b to your computer and use it in GitHub Desktop.
var alphabet = ["a","d","e","h","i"],
firstSet = ["b","c"],
secondSet = ["f","g"];
//Without Spread operator
Array.prototype.splice.apply(alphabet,[1,0].concat(firstSet)); //[a,b,c,d,e,h,i]
Array.prototype.splice.apply(alphabet,[4,0].concat(secondSet)); //[a,b,c,d,e,f,g,h,i]
console.log("Without Spread Operator: ",alphabet); //[a,b,c,d,e,f,g,h,i]
//Using Spread operator
var alphabetWithSpread = ["a",...firstSet,"d","e",...secondSet,"h","i"];
console.log("With Spread Operator: ",alphabetWithSpread); //[a,b,c,d,e,f,g,h,i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment