3 ms·
Ah ah nope! You should read MDN The default sort order is according to string Unicode code points. If compareFunction is not supplied, elements are sorted by
by andreapaiola 11y ago
Ah ah nope!
You should read MDN
The default sort order is according to string Unicode code points.
If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings in Unicode code point order. For example, "Banana" comes before "cherry". In a numeric sort, 9 comes before 80, but because numbers are converted to strings, "80" comes before "9" in Unicode order.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- glitcher 11y agoYet another reason why you shouldn't have read W3 schools.
- Klathmon 11y agoAnd just to throw another wrench in there, because it sorts by Unicode code points, capitals come before lowercase. So this: ['Banana', 'cherry', 'bagel', 'apple'].sort() Will produce this order: ["Banana", "apple", "bagel", "cherry"]