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();
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.