const arr = [ {id: 1, value : "value1", date: "2023-04-08", time: "13:11:17"}, {id: 2, value : "value2", date: "2023-04-09", time: "11:11:17"}, {id: 3, value : "value3", date: "2023-04-10", time: "17:11:17"}, {id: 4, value : "value4", date: "2023-04-10", time: "08:11:17"}, {id: 5, value : "value5", date: "2023-04-10", time: "12:11:17"}, {id: 6, value : "value6", date: "2023-04-10", time: "22:11:17"}, {id: 7, value : "value7", date: "2023-04-10", time: "17:11:17"}, {id: 8, value : "value8", date: "2023-04-11", time: "22:11:17"} ]; arr.sort((a, b) => b.date.localeCompare(a.date) || b.time.localeCompare(a.time)); console.log(arr);
//输出结果: 0: {id: 8, value: 'value8', date: '2023-04-11', time: '22:11:17'} 1: {id: 6, value: 'value6', date: '2023-04-10', time: '22:11:17'} 2: {id: 3, value: 'value3', date: '2023-04-10', time: '17:11:17'} 3: {id: 7, value: 'value7', date: '2023-04-10', time: '17:11:17'} 4: {id: 5, value: 'value5', date: '2023-04-10', time: '12:11:17'} 5: {id: 4, value: 'value4', date: '2023-04-10', time: '08:11:17'} 6: {id: 2, value: 'value2', date: '2023-04-09', time: '11:11:17'} 7: {id: 1, value: 'value1', date: '2023-04-08', time: '13:11:17'}
javascript语法如何把json文件输出到html页面上
上面是“js根据时间做升序排列(数组内)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_4191.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!