Definition and Usage The split() method is used to split a string into an array of strings. Syntax stringObject.split(separator, howm...
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 |