Does anyone know how the built-in JS function array.sort() functions internally? I mean does it change strings to numbers....etc
var keys = new Array();
keys.sort();
From the MDN docs for sort():
If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings in lexicographic ("dictionary" or "telephone book," not numerical) order. For example, "80" comes before "9" in lexicographic order, but in a numeric sort 9 comes before 80.
Refer to the answers of this question as to what algorithm is being used.
new Arrayis evil, use[]literal syntax instead..sortwill not change any element values, unless you specify a function which modifies the input. eg:keys.sort(function(x,y){x.moo=1337; y.cowsay="bar";})