Javascript String.lastIndexOf()方法
作者:--
发布时间:2019-11-20
评论:0
阅读:1
此方法调用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