Possible Duplicate:
Why is sorting modifing the original in this case?
I have 2 arrays. I want to set the second variable to the sorted version of the first.
var _myArray = ["N","T","A","W","Z","X"];
var _array02 = _myArray.sort();
document.write(_myArray+'<br>'+_array02);
What should happen: N,T,A,W,N,X<br>A,N,T,W,X,Z
What happens instead: A,N,T,W,X,Z<br>A,N,T,W,X,Z
Is this by design in JS, and if so, how do I achieve what I want?
sort()sorts the array in place. Sort a copy, if you want the original array unchanged: