const couponSourse = [
{
couponEndDate: '2021-09-01',
couponId: '789',
couponName: '5折利息折扣券',
couponStatus: '04',
},
{
couponEndDate: '2021-10-22',
couponId: '123',
couponName: '9.5折利息折扣券',
couponStatus: '01',
},
{
couponEndDate: '2021-10-10',
couponId: '456',
couponName: '9折利息折扣券',
couponStatus: '02',
},
{
couponEndDate: '2021-09-01',
couponId: '101',
couponName: '8折利息折扣券',
couponStatus: '03',
},
]
// slice 和 substring(1) 都可以
function orderData(a, b) {
return a.couponStatus.slice(1) - b.couponStatus.slice(1)
}
couponSourse.sort(orderData)
console.log(couponSourse)
// parseInt
console.log(couponSourse.sort((a,b) => {
return parseInt(a.couponStatus) - parseInt(b.couponStatus)
}))
console