JavaScript » String » split

Syntax:
object.split [delimiter]

This method splits a string into substrings and creates an array containing the resulting substrings.

This method is used to 'split' a string into an array of substrings. The array numbering starts at zero.
 
The optional delimiter argument is the character, regular expression, or substring that is used to determine where to split the string. The delimiter value is not returned as part of the array of substrings.
 
If the argument is a character or substring, it must be enclosed with in a pair of double quotes. If the argument is a regular expression, do not enclose it with double quotes. If no delimiter argument is provided, the string is not split. If the empty string, "", is used as the delimiter, the string is split between each character in the string.

Examples

Code:
myString = new String("A,B,C,D")
splitString = myString.split(",")
document.write("<BR>" + splitString[0])
document.write("<BR>" + splitString[1])
document.write("<BR>" + splitString[2])
document.write("<BR>" + splitString[3])
Output:
A
B
C
D