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"]