快速提问。 javascript 中的 .sort 方法是否自动使用 ASCII 顺序对数组中的项目进行排序。我看过示例等,但在任何地方都没有看到明确的答案。还有哪些按字母顺序对数组进行排序的替代方法?
提前致谢
最佳答案
是的。如果你看.sort()
MDN 上的方法指出了省略比较函数参数时的情况:
Specifies a function that defines the sort order. If omitted, the array is sorted according to each character's Unicode code point value, according to the string conversion of each element.
由于 Unicode 是 ASCII 的超集,所以它确实按 ASCII 顺序排序。
关于javascript - javascript 按字母顺序对数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42184177/