I'm trying to get the list of months in javascript! how can I get this done by using only javascript!
Thank you!
months() // returns a list of months in the current locale (January, February, etc.) moment. monthsShort() // returns abbreviated month names (Jan, Feb, etc.)
JavaScript Date getMonth() getMonth() returns the month (0 to 11) of a date.
The getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year).
A function to get the last Sunday of a month might be: /** * Returns last Sunday of month * * @param {Temporal. YearMonth} queryMonth - YearMonth to get last Sunday of * @returns {Temporal. Date} for last Sunday of queried month */ function getLastSunday(queryMonth) { let lastOfMonth = queryMonth.
As far as I know, you can only get the array by hard-coding it.
var monthNames = [ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ];
Or you can use some javascript library which has this list hard-coded.
Since you should be using moment to deal with dates anyway, you might as well use it here too! ;)
moment.months()
or moment.monthsShort()
(both added in 2.3.0):
const moment = require('moment');
moment.locale('en'); // sets words language (optional if current locale is to be used)
moment.months() // returns a list of months in the current locale (January, February, etc.)
moment.monthsShort() // returns abbreviated month names (Jan, Feb, etc.)
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