二维数组排序JS
作者:互联网
const downsort=(arr=[],key)=>{
var tmp=JSON.parse(JSON.stringify(arr));
tmp.sort(function(a,b){
a=!isNaN(Number(a[key]))?a[key]:a[key].charCodeAt(0);
b=!isNaN(Number(b[key]))?b[key]:b[key].charCodeAt(0);
return b-a;
});
return tmp;
}
const upsort=(arr=[],key)=>{
var tmp=JSON.parse(JSON.stringify(arr));
tmp.sort(function(a,b){
a=!isNaN(Number(a[key]))?a[key]:a[key].charCodeAt(0);
b=!isNaN(Number(b[key]))?b[key]:b[key].charCodeAt(0);
return a-b;
});
return tmp;
}
var dataList=data.DC_GROUP_LIST;
console.log(dataList);
var aa= upsort(dataList,'sequence')
标签:tmp,arr,charCodeAt,JSON,JS,二维,key,var,排序 来源: https://www.cnblogs.com/csjoz/p/16334826.html