We can create a single variable that contains string data, which this string data holds several data separated by comma.

For example, I create this string: “Andy,New York,28,Journalist”. This single string contains 4 data separated by comma. Now the problem is how to extract this 4 data from it?

The answer is using JavaScript “split” function. Here is the sample code:

By using split() function I’ve created an array variable, that each one of it indexes contains separated string data respectively. In above example, data1 which is separatedData[0] contains “Andy” and data2 contains “New York” and so on.


Habibie is an Indonesian freelance PHP, MySQL, HTML5, CSS3, JavaScript, Java, Python and C# programmer. He also do graphics design, video editing, visual effects, animation, 3D modeling and making games.

Related Post

JavaScript and comma separated string