[JavaScript] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
const arrData = [
{
"class": "区域",
"name": "茂南",
"before": 0.72826087,
"after": 0.831325301
},{
"class": "网格",
"name": "西城",
"before": 1,
"after": 0.944444444
},{
"class": "网格",
"name": "天堂",
"before": 0.740740741,
"after": 0.80141844
},{
"class": "区域",
"name": "公馆",
"before": 0.643678161,
"after": 0.75
},{
"class": "网格",
"name": "银河",
"before": 0.4,
"after": 0.62
},{
"class": "网格",
"name": "猎户",
"before": 0.476190476,
"after": 0.664634146
},{
"class": "区域",
"name": "仙女",
"before": 0.592592593,
"after": 0.753665689
},{
"class": "网格",
"name": "天门",
"before": 0.333333333,
"after": 0.525
},{
"class": "网格",
"name": "斗牛",
"before": 0.666666667,
"after": 0.756756757
},{
"class": "全市",
"name": "全市",
"before": 0.675675676,
"after": 0.784069982
}
];
console.log('排序前');
console.table(arrData);
console.log('排序后');
// 次要排序条件
arrData.sort((a,b)=>a.after-b.after);
// 首要排序条件
arrData.sort((a,b) => { return a.class.localeCompare(b.class,"zh"); });
console.table(arrData);
</script>
</body>
</html>