現在有個數組:現在要算出第一條數據和第二條數據的時間差,第二條和第三條的時間差,以此類推,后面還有很多條數據,不固定 historyList: [{
id:1,
date:'2019-01-18 14:08'
},{
id:2,
date:'2019-01-19 14:08'
},{
id:3,
date:'2019-01-20 14:08'
}]我寫到這里沒有思路了:不知道該怎么取出相鄰兩項來相減?if (ctx.historyList.length > 1) {
ctx.historyList.forEach((item, index) => { console.log(ctx.historyList[index].date)
})
}
循環數組里的相鄰項,數據怎么相減
慕容森
2019-02-03 23:01:50