• The strIndexOf() method, given two arguments: the string and a substring to search for, searches the entire calling string, and returns the index of the first occurrence of the specified substring. Given a thrid argument: a number, the method returns the first occurrence of the specified substring at an index greater than or equal to the specified number.

    Parameters

    • value: string

      The value to be checked for the seeach string

    • searchString: string

      The substring to search for in the value

    • Optional position: number

      The starting position to search from

    Returns number

    Example

    strIndexOf('hello world', '') // returns 0
    strIndexOf('hello world', '', 0) // returns 0
    strIndexOf('hello world', '', 3) // returns 3
    strIndexOf('hello world', '', 8) // returns 8

    // However, if the thrid argument is greater than the length of the string
    strIndexOf('hello world', '', 11) // returns 11
    strIndexOf('hello world', '', 13) // returns 11
    strIndexOf('hello world', '', 22) // returns 11

    strIndexOf('Blue Whale', 'Blue') // returns 0
    strIndexOf('Blue Whale', 'Blute') // returns -1
    strIndexOf('Blue Whale', 'Whale', 0) // returns 5
    strIndexOf('Blue Whale', 'Whale', 5) // returns 5
    strIndexOf('Blue Whale', 'Whale', 7) // returns -1
    strIndexOf('Blue Whale', '') // returns 0
    strIndexOf('Blue Whale', '', 9) // returns 9
    strIndexOf('Blue Whale', '', 10) // returns 10
    strIndexOf('Blue Whale', '', 11) // returns 10