JavaScript lastIndexOf方法入门实例(计算指定字符在字符串中最后一次出现的位置)
作者:junjie 时间:2024-04-18 10:54:17
JavaScript lastIndexOf 方法
lastIndexOf 方法用于计算指定的字符串在整个字符串中最后一次出现的位置,并返回该数值。其语法如下:
str_object.lastIndexOf( search, start )
参数说明:
参数 | 说明 |
---|---|
str_object | 要操作的字符串(对象) |
search | 必需。要检索的字符串 |
start | 可选。指定开始检索的位置,如省略该参数,则将从字符串的最后一个字符开始检索 |
提示:字符串是从 0 开始计数的。
lastIndexOf 方法实例
<script language="JavaScript">
var str = "www.aspxhome.com";
document.write( str.lastIndexOf( "." ) + "<br />" );
document.write( str.lastIndexOf( ".", 5 ) + "<br />" );
document.write( str.lastIndexOf( ".", 10 ) );
</script>
运行该例子,输出:
9
3
9
注意在上面第二个参数为 5 的例子中,实际找到的是第一个 . 符号,即在 www.5 字符串中搜索。
lastIndexOf 对大小写敏感,如果要检索的字符串值没有出现,则该方法返回 -1。
标签:JavaScript,lastIndexOf
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
比较详细的MySQL字段类型说明
2024-01-20 16:13:02
python实现处理Excel表格超详细系列
2021-06-22 13:34:36
![](https://img.aspxhome.com/file/2023/5/105245_0s.png)
Django forms表单 select下拉框的传值实例
2023-04-21 02:23:53
[翻译]标记语言和样式手册 chapter 6 短语元素
2008-01-25 16:37:00
![](https://img.aspxhome.com/file/UploadPic/20081/25/200812517182403s.jpg)
MySQL中的count(*) 和 count(1) 区别性能对比分析
2024-01-24 03:12:51
![](https://img.aspxhome.com/file/2023/5/93055_0s.png)
PHP获取类中常量,属性,及方法列表的方法
2023-11-19 19:57:58
python向量化与for循环耗时对比分析
2023-12-21 14:14:59
![](https://img.aspxhome.com/file/2023/0/101710_0s.png)
VBScript中LBound函数和UBound函数的用法
2008-06-27 13:02:00
SQL Server触发器及触发器中的事务学习
2024-01-27 08:48:02
![](https://img.aspxhome.com/file/2023/2/116292_0s.png)
python 解决flask 图片在线浏览或者直接下载的问题
2022-05-15 06:24:57
SQL Server 分页查询存储过程代码
2024-01-21 04:53:40
Python爬取当网书籍数据并数据可视化展示
2023-11-20 11:31:14
![](https://img.aspxhome.com/file/2023/7/76907_0s.png)
Python处理CSV与List的转换方法
2021-11-22 11:53:48
asp会员系统如何实现“忘记密码”
2007-09-19 12:17:00
js树插件zTree获取所有选中节点数据的方法
2024-05-02 16:20:55
Python3读取和写入excel表格数据的示例代码
2022-01-21 10:33:55
![](https://img.aspxhome.com/file/2023/4/114514_0s.png)
GOLANG使用Context实现传值、超时和取消的方法
2024-05-22 10:13:13
oracle sys_connect_by_path 函数 结果集连接
2009-07-12 18:48:00
python频繁写入文件时提速的方法
2023-11-11 01:48:40
windows、linux下打包Python3程序详细方法
2023-09-30 22:06:53
![](https://img.aspxhome.com/file/2023/0/62930_0s.png)