startsWith
The startsWith() method checks whether a string starts with a specific substring.
Interactive example
Syntax
Classic signature
typescript
function startsWith<
GenericString extends string,
GenericSearchString extends string
>(
input: GenericInput,
searchString: GenericSearchString
): input is Extract<GenericInput, `${GenericSearchString}${string}`>Curried signature
typescript
function startsWith<
GenericInput extends string,
GenericSearchString extends string
>(
searchString: GenericSearchString
): (
input: GenericInput
) => input is Extract<GenericInput, `${GenericSearchString}${string}`>;Parameters
input: The string to check.searchString: The substring to look for at the start ofinput.
Return value
Returns true if input starts with searchString and false otherwise.
See also
- includes: Checks whether a string contains a substring.
- indexOf: Returns the index of the first occurrence of a substring.
- lastIndexOf: Returns the index of the last occurrence of a substring.
- search: Searches for a match with a regular expression.
