This seems like a simple question but I can't find much info on this.
var array1 = new Array(4, 3, 1, 2, 0, 5);
var array2 = array1;
array2.sort(function(a, b) {
return a - b;
})
Expected behavior: array2 is sorted and array1 is in the original order starting with 4.
Actual result: both arrays are sorted.
How can I sort array1 - while maintaining array1 and storing the results of the sort in array2? I thought that doing array2 = array1
would copy the variable, not reference it. However, in Firefox's console both arrays appear sorted.