Javascript String Split Function

Javascript String Split Function

A string can be splitted in javascript by using the split() function. The split function takes the delimiter as an arguement. Whenever it sees the delimiter the string is splitted and stored in the array.

sample code:
<script type=”text/javascript”>
var myString = “Javascript string split function”;

var mySplitString = myString.split(” “);

for(i = 0; i < mySplitString.length; i++)
{
 document.write(”<br /> Element ” + i + ” = ” + mySplitString[i]);
}
</script>

In the above example the delimiter used is the space character ” “. Thus the split function splits the given string whenever it finds the space character and stores the result in the array. The result can be viewed by looping through the elements of the array with its length.

Result:
Element 0 = Javascript
Element 1 = string
Element 2 = split
Element 3 = function

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.