js根据时间做升序排列(数组内)

495 ℃
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'}

js用最简单的方法实现2个数组的交叉一对一合并

如何利用js语法将2个数组进行交叉合并

利用js语法把数组根据相同key转换成嵌套数组格式

javascript语法如何把json文件输出到html页面上

js点击按钮从服务器上下载json文件(不是打开文件)

标签: js升序排列, js时间排序

上面是“js根据时间做升序排列(数组内)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_4191.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

vuejs axios全局封装loading加载
帝国CMS7.5版支持限制单个栏目单个会员发布信息
php利用函数获取两个数组中不同元素的个数
网站建设中为什么需要图片来装饰网站?
面试题:vuejs项目中按钮级别权限怎么控制