首页 > 代码库 > javascript 中英文数组排序 sort结合localeCompare

javascript 中英文数组排序 sort结合localeCompare

var arr = new Array(6)
arr[0] = "a计划量余额";
arr[1] = "b计划发出";
arr[2] = "1计划量";
arr[3] = "强";
arr[4] = "采购倍数";
arr[5] = "计划收到";
arr[6] = "净需求";
arr[7] = "毛需求";
arr[8] = "期初库存";
arr[9] = "期末库存";
arr[10] = "已经发出";
arr[11] = "已经收到";
arr[12] = "最小库存";
arr[13] = "最小采购/生产量";
alert(arr.sort(function(a, b) {
return a.localeCompare(b)
}));

技术分享

 

javascript 中英文数组排序 sort结合localeCompare