首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

typedArray.lastIndexOf

lastIndexOf()方法返回在类型数组中可以找到给定元素的最后一个索引,如果不存在,则返回-1。 方法具有与Array.prototype.lastIndexOf()相同的算法。 TypedArray是这里的类型化数组类型之一。

语法

代码语言:javascript
复制
typedarray.lastIndexOf(searchElement[, fromIndex = typedarray.length])

参数

searchElement需要在类型化数组中定位的元素fromIndex可选。反向搜索的起始下标。默认为数组的长度,即会搜索整个类型化数组。如果下标大于等于类型化数组长度,会搜索整个类型化数组。如果是负数,则被当做距离类型化数组尾部的偏移。注:如果提供的下标是负数,类型化数组仍然从后到前搜索。如果计算出来的下标小于 0,则会返回 -1,即不会搜索类型化数组。

返回值

数组中元素的最后一个下标;没有找到则返回-1

描述

lastIndexOf使用严格相等(由 === 或三等号运算符使用的相同方法)比较searchElement和类型化数组的元素。

Examples

代码语言:javascript
复制
var uint8 = new Uint8Array([2, 5, 9, 2]);
uint8.lastIndexOf(2);     // 3
uint8.lastIndexOf(7);     // -1
uint8.lastIndexOf(2, 3);  // 3
uint8.lastIndexOf(2, 2);  // 0
uint8.lastIndexOf(2, -2); // 0
uint8.lastIndexOf(2, -1); // 3

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'TypedArray.prototype.lastIndexOf' in that specification.

Standard

Initial definition.

ECMAScript 2017 Draft (ECMA-262)The definition of 'TypedArray.prototype.lastIndexOf' in that specification.

Draft

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

(Yes)

(Yes)

37 (37)

No support

(Yes)

10

Feature

Android

Chrome for Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

No support

37 (37)

No support

No support

10

扫码关注腾讯云开发者

领取腾讯云代金券