Home > Article > Web Front-end > Introductory example of JavaScript lastIndexOf method (calculates the position of the last occurrence of the specified character in the string)_Basic knowledge
JavaScript lastIndexOf method
The lastIndexOf method is used to calculate the position of the last occurrence of the specified string in the entire string and return the value. Its syntax is as follows:
Parameter description:
参数 | 说明 |
---|---|
str_object | 要操作的字符串(对象) |
search | 必需。要检索的字符串 |
start | 可选。指定开始检索的位置,如省略该参数,则将从字符串的最后一个字符开始检索 |
Tip: String counting starts from 0.
lastIndexOf method instance
Run this example, output: