Menu

Convert Comma Delimited String to Javascript Array

Jquery By Dec 18, 2013 No Comments

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 ~~~~

Author

Hello i am Vivek Moyal PHP developer and writes tutorials for students and beginners. Love to explore new cities

No Comments

Leave a comment

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