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