我有一个事件对象。如下所示,对象始终具有当前日期和其他日期。在下面显示的对象的当前版本中,对象有2天作为键。第一天的密钥是 2018-01-26 ,第二天的密钥是 2018-01-28 。我想检查并添加不在对象中但在当前周内的所有日期的密钥。这些键将有一个空数组作为值。我怎么做 ?感谢
{
"2018-01-26": Array [
Object {
"allDay": false,
"color": "#1abc9c",
"height": 150,
"location": "University of Illinois at Urbna-Champaign",
"name": "Bsbshsjhs",
"startDate": "2018-01-26",
"startTime": "07:25 am",
"stopDate": "2018-01-26",
"stopTime": "08:25 am",
},
Object {
"allDay": false,
"color": "#1abc9c",
"height": 150,
"location": "University of Illinois at Urbna-Champaign",
"name": "Hdhrhhfj",
"startDate": "2018-01-26",
"startTime": "09:19 am",
"stopDate": "2018-01-26",
"stopTime": "10:19 am",
},
Object {
"allDay": false,
"color": "#1abc9c",
"height": 150,
"location": "University of Illinois at Urbna-Champaign",
"name": "Mmmmmmm",
"startDate": "2018-01-26",
"startTime": "09:23 am",
"stopDate": "2018-01-26",
"stopTime": "10:23 am",
},
Object {
"allDay": false,
"color": "#1abc9c",
"height": 150,
"location": "University of Illinois at Urbna-Champaign",
"name": "Gghhh",
"startDate": "2018-01-26",
"startTime": "10:41 am",
"stopDate": "2018-01-26",
"stopTime": "11:41 am",
},
],
"2018-01-28": Array [],
}
答案 0 :(得分:2)
代码将检查日期是否存在,如果没有添加空数组。
if (!eventObj[date]) {
eventObj[date] = []
}