此方法调用string对象之内返回索引指定的值最后一次出现,开始搜索在的fromindex或如果没有找到该值则返回-1。
语法
string.lastindexof(searchvalue[, fromindex])
下面是参数的详细信息:
返回值:
返回最后出现的索引,如果没有找到则为-1
例子:
<html> <head> <title>javascript string lastindexof() method</title> </head> <body> <script type="text/javascript"> var str1 = new string( "this is string one and again string" ); var index = str1.lastindexof( "string" ); document.write("lastindexof found string :" + index ); document.write("<br />"); var index = str1.lastindexof( "one" ); document.write("lastindexof found string :" + index ); </script> </body> </html>
这将产生以下结果:
lastindexof found string :29 lastindexof found string :15
如对本文有疑问, 点击进行留言回复!!
【第138期】 游戏策划:应聘前HR要求把游戏玩到30级,怎么玩?
网友评论