stringIndexOf

Modified on Wed, 02 Aug 2023

Description

Return the index of the first occurrence of the specified substring at a position greater than or equal to position, which defaults to 0.

Syntax

stringIndexOf(input, find, position)

Parameters

Input ParameterTypeDescription
inputstringThe input string to search.
findstringThe search string
position (optional)numberStart position which is optional.

Return value

Type
number

Sample

ExampleResultDescription
stringIndexOf('dog, cat, cat', 'cat')5Finds the first matched substring index
stringIndexOf('dog, cat, dog', 'lion')-1Return -1 if there is no match
stringIndexOf('dog, cat, dog', 'dog', 5)10Return first matched substring index with given start position

To view all the String functions, click here.

See Also