一个数组的多个日期拿到最大日期和最小日期

let detectionCycleList = [“2020-01-01”,“2020-01-02”,“2020-01-03”];  //日期数组
let newArr = detectionCycleList.map(ele =>{
      return new Date(ele).getTime()
 })
let minIndex = 0;
let minDate = newArr[0];
let maxIndex = 0;
let maxDate = newArr[0];
newArr.forEach((ele,index) => {
          if(ele < minDate) {
            minDate = ele;
            minIndex = index;
          }
          if(ele > maxDate) {
            maxDate = ele;
            maxIndex = index;
          }
})
//以下打印的就是最大日期和最小日期
console.log(11111, detectionCycleList[minIndex], detectionCycleList[maxIndex])
 
原文地址:https://www.cnblogs.com/web-aqin/p/13794551.html