美文网首页
字母排序

字母排序

作者: 月光_薛 | 来源:发表于2018-08-30 17:54 被阅读0次

今天做项目的时候碰到一个需要一个字母排序的功能,自己小小的写了一下,做个笔记
//字母排序
function sorts(arr) {
var obj = [];
for(var i = 65; i <= 90; i++) {
for(var j = 0; j < arr.length; j++) {
if(arr[j].nameCode == String.fromCharCode(i)) {
obj.push(arr[j]);
}
}
}
return obj;
}
//数据格式
[{
"nameCode": "D",
"arrS": [{
"id": "4afb37a7b7ae422399c3290f81853f98",
"createDate": 1535620288000,
"udateDate": 1535620288000,
"classId": "3a405e210ffd49119edde7b8b2275540",
"className": "大一班",
"teacherName": "大哥",
"remarks": "就不会计划表接口v",
"phone": "15735806069",
"nameCode": "dg"
}]
}, {
"nameCode": "X",
"arrS": [{
"id": "72171f2f8a9d49acbaeb986dfa465731",
"createDate": 1535620616000,
"udateDate": 1535620616000,
"classId": "3a405e210ffd49119edde7b8b2275540",
"className": "大一班",
"teacherName": "薛里根",
"remarks": "",
"phone": "15735806069",
"nameCode": "xlg"
}, {
"id": "9cc68fc897444f95965cadd4297c02dd",
"createDate": 1535620640000,
"udateDate": 1535620640000,
"classId": "3a405e210ffd49119edde7b8b2275540",
"className": "大一班",
"teacherName": "小夏",
"remarks": "654654654654",
"phone": "15735806069",
"nameCode": "xx"
}]
}, {
"nameCode": "G",
"arrS": [{
"id": "7d1a2c93b69a492e814eacee4161e670",
"createDate": 1535620330000,
"udateDate": 1535620330000,
"classId": "3a405e210ffd49119edde7b8b2275540",
"className": "大一班",
"teacherName": "G1",
"remarks": "5465464",
"phone": "15735806069",
"nameCode": "G1"
}]
}]

相关文章

网友评论

      本文标题:字母排序

      本文链接:https://www.haomeiwen.com/subject/ivudwftx.html