JavaScript split() Method
Complete String Object Reference
Definition and Usage
The split() method is used to split a string into an array of strings.
Syntax
stringObject.split(separator, howmany)
|
| Parameter |
Description |
| separator |
Required. Specifies the character, regular expression, or
substring that is used to determine where to split the string |
| howmany |
Optional. Specify how many times split should occur. Must
be a numeric value |
Tips and Notes
Note: If an empty string ("") is used as the separator, the string is
split between each character.
Example
In this example we will split up a string in different ways:
<script type="text/javascript">
var str="How are you doing today?";
document.write(str.split(" ") + "<br />");
document.write(str.split("") + "<br />");
document.write(str.split(" ",3));
</script>
|
The output of the code above will be:
How,are,you,doing,today?
H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?
How,are,you
|
Try-It-Yourself Demos
split()
How to use split() to split up a string.
Complete String Object Reference
Learn XML with <oXygen/> XML Editor - Free Trial!
 |
|
oXygen helps you learn to define,
edit, validate and transform XML documents. Supported technologies include XML Schema,
DTD, Relax NG, XSLT, XPath, XQuery, CSS.
Understand in no time how XSLT and XQuery work by using the intuitive oXygen debugger!
Do you have any XML related questions? Get free answers from the oXygen
XML forum
and from the video
demonstrations.
Download a FREE 30-day trial today!
|
|