如何在不区分大小写的情况下按字母排序

How do you sort alphabetical without case sensitive

本文关键字:情况下 排序 大小写 不区      更新时间:2023-09-26

如何使此alpha排序不区分大小写?我知道你应该使用toLowerCase,但我不知道怎么做。

sort_alpha: function(a,b) {
    if (a[0]==b[0]) return 0;
    if (a[0]<b[0]) return -1;
    return 1;
}

您需要将a和b转换为小写

var lower_a = a.toLowerCase();
var lower_b = b.toLowerCase();