按字母顺序对数组进行排序 [英] Sort array alphabetically javascript

查看:112
本文介绍了按字母顺序对数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速问题。 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.

这篇关于按字母顺序对数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆