我想要从第 1 天或第 1 个月开始直到今天的天和月的编号数组。
例如: 今天是 2012 年 10 月 5 日
天数数组:输出 (1,2,3,4,5)
月份数组:输出 (1,2,3,4,5,6,7,8,9,10)
这些数组将在图表的 x 轴中使用。
最佳答案
您可以将Date
对象与this useful Array.range() implementation 一起使用。获取数组;
var date = new Date("05-Oct-2012");
var days = Array.range(1, date.getDate());
console.log(days);
var months = Array.range(1, date.getMonth() + 1); // Zero-based, so add one.
console.log(months);
关于javascript - 数组中的天或月从第 1 天或第 1 个月开始编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12743507/