Split Function in Javascript

Split Function: Delimiter :-
The space character ” ” we mentioned will be our delimiter and it is used by the split function as a way of breaking up the string. Every time it sees the delimiter we specified, it will create a new element in an array. The first argument of the split function is the delimiter.

Split() Function:-
The split() function splits text and puts the pieces into an array, with each piece taking up one slot in the array. For example, if you were to split “This is some text”,the split() function would create an array with four slots (zero to 3). The first slot in the array would contain “This”, the second slot would contain “is”, the third “some” and the fourth “text”.

Example:-

 

var stringdata= "1$2$3$4";
var splitdata = stringdata.split("$");
for(i = 0; i < splitdata.length; i++)
{
   document.write("Element " + i + " = " + splitdata [i]);
}


Output
=====
Element 0 = 1
Element 1 = 2
Element 2 = 3
Element 3 = 4