JavaScript - Store comma seperated values in seperate variables

I would like to store the month and year in seperate variables. When I run the below code, I get the letter "A" stored in array monthYear[0] and "P" stored in monthYear[1]. I would like to store April in monthYear[0] and 2014 in monthYear[1]. How can I do this?

monthYear = "April, 2014"
monthYear.split(',');
alert(monthYear[0]);
LVL 1
illfusion82Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
WebDevEMConnect With a Mentor Commented:
Hi,

Saving the result of the split in another variable should do the trick...Otherwise monthYear[0] is still the first character of the original string.
monthYear = "April, 2014"
splitMY = monthYear.split(',');
alert(splitMY[0]);

Open in new window

Hope this helps!

WebDevEM
0
All Courses

From novice to tech pro — start learning today.