Split a string into an array of substrings:
The result of n will be an array with the values:
The split() method is used to split a string into an array of substrings, and returns the new array.
Tip: If an empty string ("") is used as the separator, the string is split between each character.
Note: The split() method does not change the original string.
![]()
The split() method is supported in all major browsers.
| Parameter | Description |
|---|---|
| separator | Optional. Specifies the character, or the regular expression, to use for splitting the string. If omitted, the entire string will be returned (an array with only one item) |
| limit | Optional. An integer that specifies the number of splits, items after the split limit will not be included in the array |
| Type | Description |
|---|---|
| Array | An array containing the splitted values |
| JavaScript Version: | 1.1 |
|---|
Omit the separator parameter:
The result of n will be an array with only one value:
Separate each charater, including white-space:
The result of n will be an array with the values:
Use the limit parameter:
The result of n will be an array with only 3 values:
Use a letter as a separator:
The result of n will be an array with the values:
JavaScript String Object
Your message has been sent to W3Schools.