Manipulate String Object Using JavaScript split() Method

If we often used JavaScript language for web programing, sometimes we need to manipulate string object. There are many kind of string manipulation method on JavaScript. But Now I want to play with "split()" method.

JavaScript split() method split characters in a string with the specified pattern of character(s). "split()" syntax is



This is the example using split() method :

   1: <script type="text/javascript">//<![CDATA[
   2:     var sObj ="Data1,Data2,Data3";
   3:     var aObj = sObj.split(",");
   4:     for ( var i in aObj )
   5:         {
   6:             alert( aObj[i] );
   7:         } 
   8: //]]></script>

The example above will give the alert result "Data1", then "Data2", then "Data3" without double quotes.

The result of split() method is an array. So we can use the split method to convert string object to an array object.