Function strLastIndexOf

The strLastIndexOf() method, given two arguments: the string and a substring to search for, searches the entire calling string, and returns the index of the last occurrence of the specified substring. Given a third argument: a number, the method returns the last occurrence of the specified substring at an index less than or equal to the specified number.

strLastIndexOf('canal', 'a');     // returns 3
strLastIndexOf('canal', 'a', 2); // returns 1
strLastIndexOf('canal', 'a', 0); // returns -1
strLastIndexOf('canal', 'x'); // returns -1
strLastIndexOf('canal', 'c', -5); // returns 0
strLastIndexOf('canal', 'c', 0); // returns 0
strLastIndexOf('canal', ''); // returns 5
strLastIndexOf('canal', '', 2); // returns 2
  • Parameters

    • value: string

      The value to be checked for the seeach string

    • searchString: string

      The substring to search for in the value

    • Optionalposition: number

      The starting position to search from

    Returns number