String.prototype.split() divides a string into an array of substrings by searching for a separator pattern (same API as MDN String.prototype.split()). Learn string and regex separators, the optional limit, capturing groups, empty edges, five examples, and try-it labs.
01
Kind
Instance method
02
Returns
Array of strings
03
Separator
String or RegExp
04
Limit
Optional cap
05
Mutates?
No
06
Baseline
Widely available
Fundamentals
Introduction
Need words from a sentence, columns from a CSV line, or path segments from a URL? split() cuts the string wherever a separator matches and returns an array of the pieces.
The separator can be a string (like " " or ",") or a regular expression. An optional limit stops after a fixed number of pieces. The original string never changes.
💡
Beginner tip
split and join are partners: "a-b-c".split("-") gives ["a","b","c"], and ["a","b","c"].join("-") puts them back together.
str.split(separator, limit) searches for separator and builds an ordered array of the text between matches. The separator itself is usually left out (unless a regex capturing group pulls parts of it back in).
Returns a new array; the original string is unchanged.
Omit separator to get a one-element array with the whole string.
Use "" to split into individual code units (see Unicode note below).
Use limit when you only need the first few pieces.
Foundation
📝 Syntax
General form of String.prototype.split:
JavaScript
str.split(separator)
str.split(separator, limit)
Parameters
separator — where to cut. A string, a RegExp, or an object with Symbol.split. Omit / pass undefined to return [str]. Other values are coerced to strings.
limit(optional) — non-negative integer capping how many substrings to include. Leftover text is discarded. 0 returns [].
Return value
An Array of strings (regex capturing groups may also insert matched pieces):
Examples follow MDN String.split() patterns. Use View Output or Try It Yourself for each case.
📚 Getting Started
Words, characters, and copying the whole string.
Example 1 — Basic split()
MDN demo: split a pangram by spaces, by empty string, or with no separator.
JavaScript
const str = "The quick brown fox jumps over the lazy dog.";
const words = str.split(" ");
words[3];
// "fox"
const chars = str.split("");
chars[8];
// "k"
const strCopy = str.split();
// ["The quick brown fox jumps over the lazy dog."]
Split on a known delimiter, pick the piece you need, and use join when you want a string again.
Applications
🚀 Common Use Cases
Tokenize text — words, tags, or CSV columns.
Parse paths / URLs — split on / or ?.
Read config lines — cut key/value pairs on = or :.
Take a prefix of tokens — use the limit argument.
Not for index windows — use slice() when you know start/end indexes.
Not for emoji-safe chars — prefer Array.from(str) over split("") for Unicode code points.
🧠 How split() Builds the Array
1
Read separator / limit
Treat missing separator as “keep whole string.”
Input
2
Find matches
Locate each separator (string or regex) in order.
Search
3
Collect pieces
Push text between matches (plus captures if any).
Build
4
✅
Return an array
Stop early if limit is reached; original str unchanged.
Important
📝 Notes
The separator is usually not included in the result (except regex capturing groups).
split("") splits UTF-16 code units — emoji may break into surrogates.
Leading/trailing separators create empty strings at the ends of the array.
limit discards leftover text; it does not append a “remainder” piece.
Pair with join() to rebuild a string from pieces.
Always capture the returned array — the original string is unchanged.
Compatibility
Browser & Runtime Support
String.prototype.split() is Baseline Widely available — supported across modern browsers since July 2015 (and far earlier as a core language feature).
✓ Baseline · Widely available
String.split()
Safe for production in browsers and runtimes (Node.js, Deno, Bun). Prefer split() for delimiter-based tokenization.
UniversalWidely available
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
split()Excellent
Bottom line: Use String.split() to turn text into an array of pieces. Remember limit discards leftovers, and split("") is UTF-16 — not grapheme-safe.
Wrap Up
Conclusion
String.prototype.split() is the go-to tool for turning delimited text into an array — spaces, commas, regex patterns, and optional limits included. Combine it with join() when you need a string again, and prefer slice() when you already know indexes.
Filter empty pieces when consecutive separators appear
Use Array.from(str) for Unicode-aware “characters”
❌ Don’t
Expect limit to keep a remainder chunk
Use split("") on emoji without checking surrogates
Forget trailing empties from ending separators
Mutate strings — always use the returned array
Parse complex CSV with naive split(",") (quotes break it)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about String.split()
Divide a string into an array of substrings.
5
Core concepts
📝01
Returns
Array
API
✂️02
Separator
string / regex
Input
🔢03
Limit
optional cap
Control
🔁04
Partner
join()
Pair
⚡05
Mutates
no
Immutable
❓ Frequently Asked Questions
String.prototype.split(separator, limit?) divides a string into an ordered list of substrings and returns them in an Array. The original string is unchanged.
Omitting separator (or passing undefined) returns a one-element array containing the whole string — for example "hi".split() is ["hi"].
An empty-string separator splits into UTF-16 code units (roughly “characters” for BMP text). Be careful with emoji — surrogate pairs can break. Prefer Array.from(str) or [...str] for Unicode code points.
limit is a non-negative integer capping how many pieces go into the array. Leftover text is discarded. limit 0 returns [].
Yes. Pass a RegExp as separator. If the regex has capturing groups, those captures are included in the result array.
Use Array.prototype.join(). For example "a,b,c".split(",").join("-") returns "a-b-c".
Did you know?
"".split("") is the only way to get an empty array when the separator is a string and limit is not 0. And if a regex separator has capturing groups, those captures are spliced into the result — a feature many beginners discover by accident.