slice
The slice() method extracts a section of a string and returns a new string without modifying the original string.
Interactive example
Syntax
Classic signature
typescript
function slice<
GenericInput extends string
>(
input: GenericInput,
start: number,
end: number
): stringCurried signature
typescript
function slice<
GenericInput extends string
>(
start: number,
end: number
): (input: GenericInput) => stringParameters
input: The string to extract from.start: The start index of the extraction (inclusive). If negative, counts from the end.end: The end index of the extraction (exclusive). If negative, counts from the end.
Return value
A new string containing the section extracted from the original string.
See also
substring- Extracts a substring between two indexescharAt- Returns the character at an indexat- Returns the character at an index with negative index support
