Skip to content

Instantly share code, notes, and snippets.

@malexandre
Created December 18, 2014 17:03
Show Gist options
  • Save malexandre/6061ef7cea98462f8709 to your computer and use it in GitHub Desktop.
Save malexandre/6061ef7cea98462f8709 to your computer and use it in GitHub Desktop.
Copy an array into another that already exists (like 'dest = src;', except that it keeps the reference to the existing array)
function copyArray(src, dest)
{
// (performance: http://jsperf.com/empty-javascript-array & http://jsperf.com/array-extending-push-vs-concat)
while(dest.length > 0)
{
dest.pop();
}
if (src)
{
for (var i = 0; i < src.length; ++i)
{
dest.push(data.Search[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment