gpt4 book ai didi

javascript - Angular 如何对数组的日期对象进行排序?

转载 作者:行者123 更新时间:2023-11-30 19:01:08 24 4
gpt4 key购买 nike

<分区>

我正在尝试弄清楚如何对一个包含 Date 对象的数组进行排序。

下面是我的数组 Appointment[](包含 3 个对象)

0: {id: 36, appointmentDate: "2019-12-27T10:28:15"}
1: {id: 57, appointmentDate: "2020-01-03T08:29:25"}
2: {id: 58, appointmentDate: "2020-01-15T15:45:19"}

这是我尝试实现但没有奏效的方法 a.appointmentDate.getTime 不是函数

if(param === 'a'){
return value.sort((a, b) => { return a.appointmentDate.getTime() - b.appointmentDate.getTime() });
}

下面说的另一种方法也不起作用

算术运算的左侧必须是“any”、“number”、“bigint”或枚举类型

  if(param === 'a'){
return value.sort((a, b) => { return new Date(a.appointmentDate) - new Date(b.appointmentDate});
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com