js根据数组中对象的多个属性值进行排序
seatList.sort(function (a, b) {
if (a['ordinate'] === b['ordinate']) {
if (a['abscissa'] > b['abscissa']) {
return 1
} else if (a['abscissa'] < b['abscissa']) {
return -1
} else {
return 0
}
} else {
if (a['ordinate'] > b['ordinate']) {
return 1
} else {
return -1
}
}
})
解释:将数组按照纵坐标(ordinate)排序,当纵坐标相等时,按照横坐标(abscissa)排序;