Skip to main content
deleted 41 characters in body; edited tags; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

How to This Make JavaScript Switch Statement More Succint Determine numeric month based on actual moth

The following script uses a switch statement to determine the numeric month based on the actual month. Is there a more succinct way (read: elegant, or less time to write) to accomplish the same result? Is there a down-side or up-side to either approach? Thank you for your help. Please find attached  

fiddlejsFiddle

How to This Make JavaScript Switch Statement More Succint

The following script uses a switch statement to determine the numeric month based on the actual month. Is there a more succinct way (read: elegant, or less time to write) to accomplish the same result? Is there a down-side or up-side to either approach? Thank you for your help. Please find attached fiddle

Determine numeric month based on actual moth

The following script uses a switch statement to determine the numeric month based on the actual month. Is there a more succinct way (read: elegant, or less time to write) to accomplish the same result? Is there a down-side or up-side to either approach? 

jsFiddle

Post Migrated Here from stackoverflow.com (revisions)
Source Link
Arkady
Arkady

How to This Make JavaScript Switch Statement More Succint

The following script uses a switch statement to determine the numeric month based on the actual month. Is there a more succinct way (read: elegant, or less time to write) to accomplish the same result? Is there a down-side or up-side to either approach? Thank you for your help. Please find attached fiddle

var month = "May"; 
            var m;
            switch(month) {
                case "January":
                    m = 0;
                    break;
                case "February":
                    m = 1;
                    break;
                case "March":
                    m = 2;
                    break;
                case "April":
                    m = 3;
                    break;
                case "May":
                    m = 4;
                    break;
                case "June":
                    m = 5;
                    break;
                case "July":
                    m = 6;
                    break;
                case "August":
                    m = 7;
                    break;
                case "September":
                    m = 8;
                    break;
                case "October":
                    m = 9;
                    break;
                case "November":
                    m = 10;
                    break;
                case "December":
                    m = 11;
                    break;
                default:
                //
            }
        console.log(m);