扫码一下
查看教程更方便
lastindexof() 方法可返回一个指定的字符串值最后出现的位置,如果指定第二个参数 start,则在一个字符串中的指定位置从后向前搜索。
注意: 该方法将从后向前检索字符串,但返回是从起始位置 (0) 开始计算子字符串最后出现的位置。 看它是否含有字符串。
开始检索的位置在字符串的 start 处或字符串的结尾(没有指定 start 时)。
如果没有找到匹配字符串则返回 -1 。
注意:lastindexof() 方法是区分大小写的!
提示: 你也可以参照类似方法 indexof() 。
语法如下:
string.lastindexof(searchvalue[, fromindex])
查找的字符串最后出现的位置,如果没有找到匹配字符串则返回 -1。
所有主流浏览器都支持 lastindexof() 方法。
javascript string lastindexof() method
输出结果:
lastindexof found string :29
lastindexof found string :15