for循环抛出错误中数组的索引变量



我想根据索引比较curr_item数组的开始日期,但是我在箭头标记的行处得到这个特定的错误。我不知道是什么问题:(

0:对象start_time:"2021 - 10 - 27 - t13:30:00.000 + 05:30"end_time:"2021 - 10 - 27 - t13:45:00.000 + 05:30"1:对象start_time:"2021 - 10 - 27 - t13:46:00.000 + 05:30"end_time:"2021 - 10 - 27 - t14:00:00.000 + 05:30"2:对象start_time:"2021 - 10 - 27 - t14:00:00.000 + 05:30"end_time:"2021 - 10 - 27 - t15:02:00.000 + 05:30"


for (let index = 0; index < possible_slots; index++) {
if (
curr_time.toMillis() ===
-----> DateTime.fromISO(curr_item[index].start_time).toMillis() <-----
) {
slotlist.push({
start_time: DateTime.fromISO(curr_item[index].start_time).toISO(),
end_time: DateTime.fromISO(curr_item[index].end_time).toISO(),
name: `asd`
});
} else {
slotlist.push({
start_time: DateTime.fromISO((curr_item[index]).start_time).toISO(),
end_time: DateTime.fromISO(curr_item[index].end_time).toISO(),
hole: `true${index}`
});
curr_time = DateTime.fromISO(slotlist[slotlist.length - 1].end_time);
}
curr_item[index] = curr_item[index + 1];
}

错误:不能读取未定义的属性(读取'start_time')

这只有两个原因:

  1. 数组是根据你的代码curr_item是未定义的。2.您试图在curr_item数组中访问的索引在数组中不可用。这意味着curr_item[index]给出了undefined,当你试图访问上面语句的start_time时,它会抛出错误。

相关内容

  • 没有找到相关文章

最新更新