String object-> lastIndexOf () method

1. Definition and usage

  The lastIndexOf () method returns the last position of a specified string value. If the second parameter start is specified, the specified position in a string is searched from back to front.

  grammar:

    string.lastIndexOf(searchvalue,start)

      parameter:

        searchvalue: Specifies the string value to be retrieved.

        start: Specifies the position in the character string to start the search. If this parameter is omitted, the search will start from the last character of the string.

  Note:  This method will retrieve the string from back to front, but the return is to calculate the last occurrence of the substring from the starting position (0). See if it contains a string.

      The search start position is at the start of the string or the end of the string (when start is not specified).

      If no matching string is found, -1 is returned.

      The lastIndexOf () method is case sensitive!

  Examples:

var str = 'abbc'
console.log(str.lastIndexOf('b'))

  Output:

Guess you like

Origin www.cnblogs.com/abner-pan/p/12701063.html