Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JavaScript - Store comma seperated values in seperate variables

Posted on 2014-04-25
1
Medium Priority
?
225 Views
Last Modified: 2014-04-25
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]);
0
Comment
Question by:illfusion82
1 Comment
 
LVL 9

Accepted Solution

by:
WebDevEM earned 2000 total points
ID: 40023449
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question