endsWith
The endsWith() method checks whether a string ends with a specific substring, taking an optional position into account.
Interactive example
Syntax
Classic signature
typescript
function endsWith<
GenericInput extends string,
GenericSearchString extends string
>(
input: GenericInput,
searchString: GenericSearchString
): input is Extract<GenericInput, `${string}${GenericSearchString}`>;Curried signature
typescript
function endsWith<
GenericSearchString extends string,
GenericInput extends string
>(
searchString: GenericSearchString
): (
input: GenericInput
) => input is Extract<GenericInput, `${string}${GenericSearchString}`>;Parameters
input: The string to check.searchString: The substring to look for at the end ofinput.
Return value
A boolean indicating whether input ends with searchString. The return type uses a conditional type assertion to narrow the type of input when the condition is true.
See also
- matchAll: Retrieves all matches of a regular expression with their groups.
- match: Retrieves matches of a regular expression.
- search: Searches for a match with a regular expression.
- lastIndexOf: Returns the index of the last occurrence of a substring.
