JavaScript String.prototype.split() Method
The split() method divides a string into an array of pieces, splitting it wherever a separator appears.
Description
The split() method divides a string into an array of substrings wherever the separator appears. The separator can be a string or a regular expression; with '', the string is split into UTF-16 code units. It's the opposite of Array.prototype.join().
Splitting into characters with '' breaks emoji apart; [...str] or Array.from(str) keeps code points together.
When the separator is a regular expression with capture groups, the captured text is included in the result, which can be used to keep the separators. Splitting an empty string with a non-empty separator returns [''], not an empty array, so filter out empty strings if your data might be empty. For splitting text into words or sentences in any language, Intl.Segmenter is more reliable.
Syntax
string.split(separator)
string.split(separator, limit)Parameters
- separatorThe string or regular expression to split at. If left out, the result is an array with the whole string.
- limitOptional. The maximum number of pieces to return.
Return Value
An array of strings.
Example
Browser Support
The following information will show you the current browser support for the String.prototype.split() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





