博学而笃志 切问而近思 仁在其中
详情
Javascript String.lastIndexOf()方法
作者:--     发布时间:2019-11-20     评论:0     阅读:1

此方法调用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  

 



下一篇:测试
相关文章
loading......
最新动态
所有评论

loading......

网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册