An alternative to Array.prototype.indexOf is an object:
var months = {jan: 0, feb:1, mar:2 ...}; var monthName = 'January'; var monthNum = months[monthName.substring(0,3).toLowerCase()];
The advantage is that you can take various forms of the month name, such as Jan, jan, JAN, January, JANUARY, etc.
Oh, the above assumes you need a month number, as for entering a javascript date constructor. To get the month number of the calendar, simply increase the values ββby 1.
source share