Javascript Split Function
Like this blog? Consider exploring one of our sponsored banner ads...
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:
[js]var colorString = “red|orange|blue|white|black|brown”;[/js]
Which is obviously a simple a pipe-delimited string of colors. So to make this into an array we would use the split function.
[js]var colorArray = colorString.split(“|”);[/js]
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…
[js]
var message = “My favorite color is ” + colorArray[3] ;
alert(message);
[/js]
About this entry
You’re currently reading “Javascript Split Function,” an entry on BRADINO
- Published:
- 11.20.07 / 3am
- Category:
- JavaScript
- Tags:
No comments
Jump to comment form | comments rss [?]