How to subtract the data from the adjacent items in a circular array

now there is an array: now we need to calculate the time difference between the first data and the second data, the time difference between the second and the third, and so on, and there are many pieces of data that are not fixed

.
 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"
      }]

I have no idea at this point: I don"t know how to subtract two adjacent items.

if (ctx.historyList.length > 1) {
            ctx.historyList.forEach((item, index) => {
              console.log(ctx.historyList[index].date)
            })
          }
May.06,2022

let result = [];
historyList.reduce((pre, curr) => {
    if (pre) {
        result.push(new Date(curr.date) - new Date(pre));
    }
    return curr.date;
}, 0);

result is millisecond interpolation. If you need other processing, do it before push. Such as converting to other formats


unix timestamp know.

< hr class= answer >
   

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e8d9-2c417.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e8d9-2c417.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?