I am using momentjs and am trying to create an array containing the last 30 days.
I think I can do this be creating a counter and then counting backwards, creating a moment for each day.
But is this the best method? Does anybody know if momentjs has a function built in that can already do this?
As best I know, momentjs doesn't have any built in features for automatically creating an array containing moment instances, but you can easily construct an array of the previous thirty days using a short statement like this:
const lastThirtyDays = [...new Array(30)].map((i, idx) => moment().startOf("day").subtract(idx, "days"));
momentjs also has the ability to create objects that represent durations if that's of any help to you with your current problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With