javascript - javascript 按字母顺序对数组进行排序

标签 javascript arrays sorting

快速提问。 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/

相关文章:

c++ - 在cpp中查找二维字符串数组长度的函数?

python - 将 2d 转换为 3d 数组后保存图像问题

java - 在特定布局中添加矩阵

sorting - OCaml - 如何对对进行排序?

java - 使用 Stream 按给定索引序列排序

javascript - Google Autocomplete API - 格式化输出结果

javascript - 如何在 HTML5 Audio 中控制播放和暂停

java - 从 int 数组中删除重复元素

javascript - 如何遍历对象并将键插入数组?

javascript - $.ajax 表单使用 JSONP 提交到 Google Docs : "Resource interpreted as Script but transferred with MIME type text/html"