JavaScript中的lastIndexOf()方法使用详解

网络编程 发布日期:2024/10/6 浏览次数:1

正在浏览:JavaScript中的lastIndexOf()方法使用详解

 此方法调用String对象之内返回索引指定的值最后一次出现,开始搜索在的fromIndex或如果没有找到该值则返回-1。
语法

string.lastIndexOf(searchValue[, fromIndex])

下面是参数的详细信息:

  •     searchValue : 一个字符串,表示要搜索的值
  •     fromIndex : 在调用字符串内的位置,从开始搜索。它是介于0-字符串的长度任意整数。缺省值是0。

返回值:

返回最后出现的索引,如果没有找到则为-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 

Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。