Using moment js to create an array with days of the week and hours of the day?
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
Here's a little snippet to get the (locale-specific) names of the days of the week from Moment.js:
var weekdayNames = Array.apply(null, Array(7)).map( function (_, i) { return moment(i, 'e').format('dddd'); });console.log(weekdayNames);// Array [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
If you want the week to start on Monday, replace moment(i, 'e')
with moment(i+1, 'e')
.