快速问题。 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?
预先感谢
推荐答案是。如果您查看 MDN上的.sort() 方法指出省略了比较功能参数的情况:
Yes. If you look at the .sort() method on MDN it states the case when the compare function parameter is omitted:
指定一个定义排序顺序的函数。如果省略,则根据每个字符的Unicode代码点值和每个元素的字符串转换对数组进行排序。
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.
是ASCII的超集,是的,它的确按ASCII顺序排序。
Since Unicode is a super set of ASCII then yes it does sort in ASCII order.
更多推荐
按字母顺序对数组进行排序
发布评论