indexOf
The indexOf() method returns the index of the first occurrence of a substring in a string, or undefined if the substring is not found.
Interactive example
Syntax
Classic signature
typescript
function indexOf(
input: string,
searchString: string,
position?: number
): number | undefined;Curried signature
typescript
function indexOf<
GenericInput extends string
>(
searchString: string
): (input: GenericInput) => number | undefined;Parameters
input: The string in which to search.searchString: The substring to search for.position(optional): The position in the string from which to start searching. Defaults to 0.
Return value
The index of the first occurrence of the substring, or undefined if the substring is not found.
See also
- includes: Checks whether a string contains a substring.
- search: Searches for a match with a regular expression.
- match: Retrieves matches of a string with a regular expression.
