JavaScript (ES2026) reference · String Methods
JavaScript String split() Method
Split a string into an array of substrings at each separator (a string or regex), with an optional limit.
JavaScript (ES2026) Since ES3
Syntax
string.split(separator, limit)
Parameters
| Parameter | Description |
|---|---|
separator |
A string or regular expression. |
limit optional |
Maximum number of pieces. |
Return value
An array of strings.
Examples
console.log("a,b,,c".split(","));
console.log("one two three".split(/\s+/));
console.log("abc".split(""));
Output
[ 'a', 'b', '', 'c' ] [ 'one', 'two', 'three' ] [ 'a', 'b', 'c' ]
const [key, ...rest] = "name=Ada=Lovelace".split("=");
console.log(key, rest.join("="));
console.log("a b c d".split(" ", 2));
Output
name Ada=Lovelace [ 'a', 'b' ]
Version history
| Version | Change |
|---|---|
| JavaScript ES3 | Added |
In other languages
str.split()· Pythonexplode()· PHPstr_split()· PHP
Related
array.join()· Join all elements into one string, separated by commas or by a separator you choose.string.slice()· Extract part of a string between two indexes; negative indexes count from the end.string.trim()· Remove whitespace (spaces, tabs, line breaks) from both ends of a string.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial