json对象的值按照中文首字母排序

var finalArr=[], chars=[],list= [];
for(var i=0;i<thatData.length;i++){//类别下拉框排序
    if(/^[\u4e00-\u9fa5]*$/.test(thatData[i].categoryName.charAt(0))) {
		finalArr.push(thatData[i]);   // 类别名称为中文的
	}else {
		chars.push(thatData[i]);   // 类别名称非中文的(字母,数字)
	}
}
chars.sort((a,b) => a.categoryName.charCodeAt(0)-b.categoryName.charCodeAt(0));
finalArr.sort((a,b) => a.categoryName.localeCompare(b.categoryName));
list = chars.concat(finalArr); // list为最终数组
console.log(list)

注:这里的thatData是一个json对象

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值