
生成365天日期数组,填写已存日期
问题:已知一个日期数组,如何生成一个365天的数组,并将已有的日期填充到对应的位置,空缺日期留空?
解决方案:
function getdatearray(activedates) {
const datearray = [];
for (let i = 0; i < 365; i++) {
const date = new date(2019, 0, 1);
date.setdate(date.getdate() + i);
const datestr = date.tolocaledatestring();
if (activedates.includes(datestr)) {
datearray.push(datestr);
} else {
datearray.push('');
}
}
return datearray;
}示例:
立即学习“Java免费学习笔记(深入)”;
const arr = ["2019/1/1", "2019/1/4", "2019/1/6"]; console.log(getdatearray(arr));
输出:
["2019/1/1", "", "", "2019/1/4", "", "2019/1/6", ...]
以上就是如何用JavaScript生成包含已知日期的365天日期数组?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号