gpt4 book ai didi

javascript - 如何使用 From 和 To 键短接时序阵列数据

转载 作者:行者123 更新时间:2023-11-28 11:44:40 25 4
gpt4 key购买 nike

这是 24 小时格式的随机计时数据的 JSON

var timeArray = [
{from: "17:00:00", to: "18:00:00"},
{from: "09:45:00", to: "14:30:00"},
{from: "20:00:00", to: "23:45:00"}];

预期输出排序如下

var timeArray = [
{from: "09:45:00", to: "14:30:00"},
{from: "17:00:00", to: "18:00:00"},
{from: "20:00:00", to: "23:45:00"}];

是否有任何逻辑或函数可以在 JavaScript 或 AngularJS 中实现此目的?

最佳答案

var timeArray = [
{ from: "09:45:00", to: "14:30:00" },
{ from: "17:00:00", to: "18:00:00" },
{ from: "20:00:00", to: "23:45:00" }
];
console.log(timeArray.sort((a, b) => b.from > a.from ? -1 : 1))

关于javascript - 如何使用 From 和 To 键短接时序阵列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54473773/

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