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 Java, C#, PHP, MySQL, HTML5, CSS3 & JavaScript programmer. He is also a good graphic designer, video editor, animator and 3D modeler.

Related Post

JavaScript and comma separated string