When javacript's sort does not add a function, does it convert each item in the array into a string, and then compare the ASCII of the first character of each substring?

const numArr = [2, 4, 8, 609545, 2, 8, 4, 1, 10, 123, 99];
const strArr = ["what", "We", "have", "lost", "will", "never"];
console.log(strArr.sort());
console.log(numArr.sort());

clipboard.png

Mar.05,2021

The sort () method sorts the elements of an array in place and returns the array. The sort is not necessarily stable. The default sort order is according to string Unicode code points.

is Unicode,. Other languages also need sorting.

Array.prototype.sort ()


sorted by Unicode

strArr = strArr.sort((a,b)=>a-b);
Menu