gpt4 book ai didi

javascript - 对工作日的对象进行排序,例如星期日、星期一、...、星期六

转载 作者:行者123 更新时间:2023-11-30 06:57:49 28 4
gpt4 key购买 nike

<分区>

如何按工作日对工作日的 Javascript 对象进行排序,即这里是对象的 JSON 格式:

 {"Friday":["5:00pm to 12:00am"] ,"Wednesday":["5:00pm to 11:00pm"],"Sunday":["11:00am to 11:00pm"], "Thursday":["5:00pm to 11:00pm"],"Saturday":["11:00am to 12:00am"]}

关键是日期,即“星期三”。我想根据工作日的顺序对其进行排序,即星期日、星期一、星期二等

预期输出是:

{ "Wednesday":["5:00pm to 11:00pm"], "Thursday":["5:00pm to 11:00pm"], "Friday":["5:00pm to 12:00am"], "Saturday":["11:00am to 12:00am"], "Sunday":["11:00am to 11:00pm"]}

这就是我正在尝试的。

var keys = {}; 
Object.keys(scope.daySpecificHours)
.map(function (k) { return [k, scope.daySpecificHours[k]]; })
.sort(function (a, b) {
if (a[0] < b[0]) return -1;
if (a[0] > b[0]) return 1;
return 0;
})
.forEach(function (d) {
scope.daySpecificHours[d[0]] = d;
});

谢谢。

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