最近七天時間組成的數組(不包含當天)
const arr=[] for (let i = 0; i < 7; i++) { const time = new Date(new Date().setDate(new Date().getDate() + i - 7)); const year = time.getFullYear(); const month = `0${time.getMonth() + 1}`.slice(-2); const strDate = `0${time.getDate()}`.slice(-2); arr.push(`${year}-${month}-${strDate}`); }
指定長度的隨機數組成的數組
let arr = [];
for (let i = 0; i < length; i++) {-----length:隨機數組的長度
var random = Math.floor(Math.random() * 100);
arr.push(random);
}