powerdong / myProblems

我用到了,你可能用到
0 stars 1 forks source link

对时间对象进行排序 #26

Open powerdong opened 4 years ago

powerdong commented 4 years ago
const arr = [{
startTime: "02:00"
stopTime: "05:00"
}, {
startTime: "08:00"
stopTime: "10:00"
},  {
startTime: "18:00"
stopTime: "19:00"
}, {
startTime: "07:00"
stopTime: "09:00"
}]

需要对startTime排序,

arr1.sort((a, b) => {
        return a.startTime.localeCompare(b.startTime)
      })