Javascript Split Function
The Javascript split() function works much the same as the php split() or explode() functions. Basically you take a string at break it up everywhere the delimiter character occurs and return the new strings in an array. So for example, let's say you have a string like this:
[script]var colorString = "red|orange|blue|white|black|brown";[/script]
Which is obviously a simple a pipe-delimited string of colors. So to make this into an array we would use the split function.
[script]var colorArray = colorString.split("|");[/script]
Now you have a simple array of colors and can access them as you would any array, either in a loop or by the numeric index, whatever...
[script]
var message = "My favorite color is " + colorArray[3] ;
alert(message);
[/script]
You’re currently reading “ Javascript Split Function ,” an entry on BRADINO
- Published:
- 11.20.07 / 3am
- Category:
- JavaScript












