按字母顺序排序数组javascript(Sort array alphabetically javascript)

编程入门 行业动态 更新时间:2024-10-26 10:27:52
按字母顺序排序数组javascript(Sort array alphabetically javascript)

快速的问题。 javascript中的.sort方法是否使用ASCII顺序自动对数组中的项进行排序。 我看了一些例子,但没有看到任何确定的答案。 还有什么替代方法按字母顺序排序数组?

提前致谢

quick question. Does the .sort method in javascript automatically sort items in an array using ASCII order. I've looked at examples etc but haven't seen a definitive answer anywhere. Also what alternative ways of alphabetically sorting an array is there?

Thanks in advance

最满意答案

是。 如果你在MDN上查看.sort()方法,它会说明省略compare函数参数的情况:

指定定义排序顺序的函数。 如果省略,则根据每个元素的字符串转换,根据每个字符的Unicode代码点值对数组进行排序。

由于Unicode是一组超级ASCII,因此它按ASCII顺序排序。

Yes. If you look at the .sort() method on MDN it states the case when the compare function parameter is omitted:

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.

Since Unicode is a super set of ASCII then yes it does sort in ASCII order.

更多推荐

本文发布于:2023-08-05 06:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字母   顺序   javascript   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!