【发布时间】:2020-06-19 09:20:55
【问题描述】:
这是我迄今为止尝试过的。
除了我不知道如何更改第一个和最后一个日期键之外,还有哪些可行?
const dates: any = [
'2020-06-24',
'2020-06-25',
'2020-06-26',
'2020-06-27',
'2020-06-28',
'2020-06-29',
'2020-06-30',
];
const dateArrayToObject = () => {
const dateObject = dates.reduce(
(acc: string, date: string) =>
Object.assign(acc, {
[date]: { selected: true, marked: true },
}),
{}
);
return dateObject;
};
【问题讨论】:
-
您的预期结果是什么?
-
第一个[date]:{startingDay:true,marked:true}和最后一个第一个[date]:{endingDay:true,marked:true},
标签: javascript arrays object javascript-objects reduce