我在unix中有两个日期:
let start: number = 1632988953;
const end: number = 1638259353;
我需要迭代这两个日期,它将在每次迭代中计算新的start
日期。
因此,我有一个如下所示的while
结构:
const datesArray = [];
while (start <= end) {
let newDate = dayjs.unix(start).add(5, 'day').unix();
datesArray.push(newDate);
start = newDate;
}
当我在函数中启动这个while
时,它会无限地迭代,杀死我的浏览器,有人能告诉我这里出了什么问题吗?
发布于 2021-09-30 00:22:56
它工作得很好,执行代码片段自己看看
let start = 1632988953;
const end = 1638259353;
let condition = true;
console.log("before : ",condition);
const datesArray = [];
while (start <= end) {
let newDate = dayjs.unix(start).add(5, 'day').unix();
datesArray.push(newDate);
start = newDate;
condition = start <= end;
}
console.log("after : ",condition);
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script>dayjs().format()</script>
https://stackoverflow.com/questions/69388550
复制相似问题