Convert Comma Delimited String to Javascript Array

By | December 18, 2013

One of my reader asked me that many times we need to convert delimited string to Java-script array or vice versa. Delimiter can be comma, pipe etc so how we can do it and use it in a simple way. So today’s post is all about this question and easy to use. Lets take a look into it.




Suppose we have an array of people’s name like Guddu, Gudia, Gullu etc and we will change the javascript array to Delimited String that is pipe(|) for this we will use the below code.

Javascript Array to Delimited String

var mynames = new Array("Guddu","Gudia","Gullu");
var nameStr = mynames.join("|");
document.write('With Delimited String :- ' + nameStr);

Now we will split the delimited string which is having | . Wooo did i use split …… yes that is the function which which we are going to use lets check the magic of split().

Delimited Sting to JavascriptArray

var nameArray = new Array();
var nameArray = nameStr.split("|");

Hope you like my tutorial if you have any advice or feedback please comment below.

~~~~ HAPPY CODING ~~~~

Leave a Reply

Your email address will not be published. Required fields are marked *