Javascript教程
JavaScript基础
JavaScript Objects
JavaScript BOM
JavaScript DOM
JavaScript OOP
JavaScript Cookies
JavaScript事件
JavaScript异常
JavaScript常用

TypedArray lastIndexOf()

JavaScript TypedArray lastIndexOf()方法

JavaScript lastIndex()of方法返回值的最后位置,如果找不到该值,则返回-1。
注意:注意:从头到尾搜索字符串,但是从头开始在0位置返回索引。
lastIndexof()方法区分大小写。

语法:

array.lastIndexOf(value, start)

参数:

value:第一个参数是将在数组中搜索的值。
< strong>开始:它是指开始搜索的位置。如果参数中未提供值,则默认值为数组的长度。

返回值:

表示元素的索引,其中值是最后一次找到的值;如果找不到该值,则为-1。

浏览器支持:

浏览器 版本
Chrome
Safari
Firefox
Opera

示例

JavaScript lastIndexOf()方法
<script type="text/javascript">
 // JavaScript to illustrate lastIndexOf() method
function lidihuo() {
    // string
    var str = 'lidihuo';
    //Finding the index of the string
    var index = str.lastIndexOf('T');
    document.write(index);
}
lidihuo();
// expected output: arr[Output:4]
</script>
输出:
4

示例2

JavaScript lastIndexOf()方法
<script type="text/javascript">
 // JavaScript to illustrate lastIndexOf() method
function lidihuo() {
// string
 var str = 'lidihuo';
 //Finding the index of the string
 var index = str.lastIndexOf('s');
 document.write(index);
}
lidihuo();
// expected output: arr[Output:-1]
</script>
输出:
-1
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4