js的sort不加函数的时候是将数组里面的每个item转换为字符串,然后比较每个子字符串第一个字符的

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

https://img3.mukewang.com/5c9db9ee0001235a03850084.jpg

杨__羊羊
浏览 492回答 2
2回答

ITMISS

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.是Unicode,别的语言也需要排序。Array.prototype.sort()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript