Skip to content

Instantly share code, notes, and snippets.

@aaroneiche
Created May 4, 2017 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaroneiche/98e74ab865e3d1ec6bf3498850d7c2f1 to your computer and use it in GitHub Desktop.
Save aaroneiche/98e74ab865e3d1ec6bf3498850d7c2f1 to your computer and use it in GitHub Desktop.
function myfunc(arg,arg2,arg3,arg4){
console.log(arg);
console.log(arg2);
console.log(arg3);
console.log(arg4);
}
myfunc("test","test2","test3","test4"); //The typical way to do it.
args = ["test","test2","test3","test4"];
myfunc(args); //You can't do this!
myfunc.apply(null,args); //You could do this
myfunc(...args); //but isn't this easier?
//======
//Add some arrays:
var mid = ["song","that","never"];
var lyrics = ["this","is","the",...mid,"ends"];
console.log(...lyrics);
console.log(lyrics.join(" "));
//console.log(...lyrics);
//======
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment