Wondering if there was a way to get momentjs or just use pure javascript to create an array of everyday of the week, and every hour in a day so that I dont have to hardcode it.
So instead of manually doing
weekArray = ["Monday", "Tuesday", "Wednesday" ....]
I'm looking for a way to do something like
weekArray = moment.js(week)
The same idea for times during the day especially, so I could potentially use different formats.
For weekdays, you could use moment's weekdays method
weekArray = moment.weekdays()
I use this solution:
var defaultWeekdays = Array.apply(null, Array(7)).map(function (_, i) {
return moment(i, 'e').startOf('week').isoWeekday(i + 1).format('ddd');
});
I got result:
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
You can Modify .format(string) to change the days format. E.g 'dddd' will shows:
["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
Check Moment.js documentation for more advanced format
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