Let\'s suppose I wanted a sort function that returns a sorted copy of the inputted array. I naively tried this
function sort(arr) { return arr.sort(); } >
You can use slice with no arguments to copy an array:
var foo, bar; foo = [3,1,2]; bar = foo.slice().sort();