Consider I have an array of dates eg:
abc = [new Date("2015-03-01"),new Date("2015-03-02"),new Date("2015-03-03"),new Date("2015-03-04")]
output:
[Sun Mar 01 2015 05:30:00 GMT+0530 (India Standard Time), Mon Mar 02 2015 05:30:00 GMT+0530 (India Standard Time), Tue Mar 03 2015 05:30:00 GMT+0530 (India Standard Time), Wed Mar 04 2015 05:30:00 GMT+0530 (India Standard Time)]
I'm trying to push the difference between two dates and trying to store the data in a new array. Here is what I have tried,
var arr = [];
abc = [new Date("2015-03-01"),new Date("2015-03-01"),new Date("2015-03-02"),new Date("2015-03-03"),new Date("2015-03-04")];
for (let i = 0; i < abc.length-1; i++){
arr.push((abc[i+1].getDate() - abc[i].getDate())+1)
}
And the output I'm getting is:
[1,2, 2, 2]
But I needed the output something like
[1,2,3,4]
I need to append plus one to each date difference. How can I achieve that?