如何從日期數組中找出最小和最大日期?目前,我建立一個這樣的數組:javascript
var dates = []; dates.push(new Date("2011/06/25")) dates.push(new Date("2011/06/26")) dates.push(new Date("2011/06/27")) dates.push(new Date("2011/06/28"))
代碼用IE,FF,Chrome測試並正常工做:java
var dates=[]; dates.push(new Date("2011/06/25")) dates.push(new Date("2011/06/26")) dates.push(new Date("2011/06/27")) dates.push(new Date("2011/06/28")) var maxDate=new Date(Math.max.apply(null,dates)); var minDate=new Date(Math.min.apply(null,dates));
**Use Spread Operators| ES6 **數組
let datesVar = [ 2017-10-26T03:37:10.876Z, 2017-10-27T03:37:10.876Z, 2017-10-23T03:37:10.876Z, 2015-10-23T03:37:10.876Z ] Math.min(...datesVar);