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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.split(separator, limit)

Parameters

ParameterDescription
separator A string or regular expression.
limit optional Maximum number of pieces.

Return value

An array of strings.

Examples

Common separatorsTry it yourself
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' ]
Split once, or with a limitTry it yourself
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

VersionChange
JavaScript ES3Added

In other languages

Was this page helpful?