Skip to content

Instantly share code, notes, and snippets.

@nwillems
Last active August 29, 2015 14:23
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 nwillems/d55494163dfccc08c185 to your computer and use it in GitHub Desktop.
Save nwillems/d55494163dfccc08c185 to your computer and use it in GitHub Desktop.
Javascript Clone array
// Fire away with comments - I'd like to know faster or more compact
// or what-ever-measure-you-like solutions
function clone(a){
return Array.apply(null, a);
}
// NOTE-to-Self: DONT EVER DO "arr.length--" it WILL mutate array!
@nwillems
Copy link
Author

According to [http://jsperf.com/new-array-vs-splice-vs-slice/19] the fastest way is

return arr.concat();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment