JavaScript split() Method
Complete RegExp Object Reference
Definition and Usage
The split() method is used to split a string into an array of strings.
This method supports regular expressions.
Syntax
stringObject.split(spl,howmany)
|
| Parameter |
Description |
| spl |
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 into an array, using a regular
expression to remove any non word characters:
<script type="text/javascript">
var str = "Peter Lois Chris Meg Stewie";
var pattern = /\W+/;
result = str.split(pattern);
document.write(result);
</script>
|
Try-It-Yourself Demos
split()
How to use split() to split up a string using a regular expression.
Complete RegExp Object Reference
Whether you're new to XML or already an advanced user, the user-friendly views
and powerful entry helpers, wizards, and debuggers in XMLSpy are designed to
meet your XML and Web services development needs from start to finish.
- XML editor
- Graphical XML Schema / DTD editors
- XSLT 1.0/2.0 editor, debugger, profiler
- XQuery editor, debugger, profiler
- Support for Office Open XML (OOXML)
- Graphical WSDL editor & SOAP debugger
- Java, C#, C++ code generation
- And much more!
Download a free 30-day trial today!
Click to see a demo!
Learn what’s new in v2008
|