js獲取最近七天時間組成數組,js生成指定長度的隨機數組


最近七天時間組成的數組(不包含當天)

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);
        }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM