You can create a month name array in JavaScript using an array literal and the Array
constructor. Here’s an example using the array literal:
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
And here’s an example using the Array
constructor:
var monthNames = new Array("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
);
You can access individual elements of the array using square brackets and an index that starts at 0. For example, to access the name of the first month, you would use monthNames[0]
, which would return "January"
.
+ There are no comments
Add yours