Return to Kroll Web Design home page

JavaScript Tutorials

« Return

split method for strings

The split method breaks the specified string into an array, based on the specified delimiter. To split an array at each and every character, use the empty string "" for the delimiter, as shown in the second example below.

Code:

<script type="text/javascript">
//<![CDATA[
myString = "orange-apple-banana-pear"; myArray = myString.split("-"); document.write("myString : ", myString, "<br><br>"); for (i=0; i<myArray.length; i++) { document.write("myArray[", i, "] : ", myArray[i], "<br>"); } //]]> </script>

Output:




©2010 Kroll Web Design    davidarthurkroll@verizon.net    781.910.3694