split()
split(
str,separator,limit?):string[]
Splits a string by separator.
DEPRECATED
Use string.split() directly instead.
Parameters
str: string | null | undefined
The string to split.
separator: string | RegExp
The separator pattern.
limit?: number
The maximum number of splits.
Returns: string[]
An array of string segments.
See Also
Since
2.0.0
Also known as
split (Lodash, es-toolkit, Remeda, Ramda, Effect) · ❌ (Radashi, Modern Dash, Antfu)
Example
// ❌ Deprecated approach
split('a-b-c', '-'); // => ['a', 'b', 'c']
split('a-b-c', '-', 2); // => ['a', 'b']
// ✅ Recommended approach
'a-b-c'.split('-'); // => ['a', 'b', 'c']
'a-b-c'.split('-', 2); // => ['a', 'b']
How it works?
Splits string by separator.
Deprecated: Use string.split() directly.
Native Equivalent
// ❌ split(str, '-')
// ✅ str.split('-')
Use Cases
Split into array 📌
Split string by delimiter.
"a,b,c".split(","); // => ["a", "b", "c"]
"hello".split(""); // => ["h", "e", "l", "l", "o"]
Parse CSV
Split CSV row into values.
const values = row.split(",").map(s => s.trim());
Split path
Parse path into segments.
"/home/user/docs".split("/").filter(Boolean);
// => ["home", "user", "docs"]