I'm trying to print out an unsorted version of an array and a sorted version of array using this code:
var sortArrayNumber = function(a, b) {
return a - b;
};
var array = [5, 2, 1044, 3, 126];
var sortedArray = [];
sortedArray = array;
sortedArray.sort(sortArrayNumber);
document.write(array + " and " + sortedArray);
This is not the actual code that I'm going to use, I'm just testing it. And when I test it using jsfiddle, it outputs
2,3,5,126,1044 and 2,3,5,126,1044
But I want it to output
5,2,1044,3,126 and 2,3,5,126,1044
So, how do I stop it from doing that?
BTW, I'm self teaching myself JavaScript so my knowledge of it isn't great