Skip to content

split

The split() method divides a string into an array of substrings using a specified separator.

Interactive example

Syntax

Classic signature

typescript
function split<
	GenericInput extends string, 
	GenericSeparator extends string, 
	GenericLimit extends number
>(
	input: GenericInput, 
	separator: GenericSeparator | RegExp, 
	params?: StringSplitParams<GenericLimit>
): Split<GenericInput, GenericSeparator, GenericLimit>;

Curried signature

typescript
function split<
	GenericInput extends string, 
	GenericSeparator extends string
>(
	separator: GenericSeparator | RegExp
): (input: GenericInput) => Split<GenericInput, GenericSeparator>;

Parameters

  • input: The string to divide.
  • separator: The string or regular expression used to split the string.
  • params (optional): An object containing limit, the maximum number of splits to perform.

Return value

An array of strings. The return type is inferred thanks to the SplitString utility type.

See also

  • slice - Extracts a section of a string
  • substring - Returns a substring between two indexes
  • match - Retrieves matches of a regular expression

Sources

Released under the MIT license.