lastIndexOf()
method returns the last index at which a given element can be found in the typed array, or -1 if it is not present. The typed array is searched backwards, starting at
fromIndex
. This method has the same algorithm as
Array.prototype.lastIndexOf()
.
TypedArray
is one of the
typed array types
here.
typedarray.lastIndexOf(searchElement[, fromIndex = typedarray.length])
searchElement
Element to locate in the typed array.
fromIndex
Optional. The index at which to start searching backwards. Defaults to the typed array's length, i.e. the whole typed array will be searched. If the index is greater than or equal to the length of the typed array, the whole typed array will be searched. If negative, it is taken as the offset from the end of the typed array. Note that even when the index is negative, the typed array is still searched from back to front. If the calculated index is less than 0, -1 is returned, i.e. the typed array will not be searched.
The last index of the element in the array;
-1
若找不到。
lastIndexOf
compares
searchElement
to elements of the typed array using
strict equality
(the same method used by the ===, or triple-equals, operator).
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
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'TypedArray.prototype.lastIndexOf' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
lastIndexOf
|
Chrome 45 | Edge 14 |
Firefox
37
|
IE No | Opera 32 | Safari 10 | WebView Android 45 | Chrome Android 45 |
Firefox Android
37
|
Opera Android 32 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 4.0.0 |
完整支持
不支持
见实现注意事项。
TypedArray
TypedArray.from()
TypedArray.of()
TypedArray.prototype.copyWithin()
TypedArray.prototype.entries()
TypedArray.prototype.every()
TypedArray.prototype.fill()
TypedArray.prototype.filter()
TypedArray.prototype.find()
TypedArray.prototype.findIndex()
TypedArray.prototype.forEach()
TypedArray.prototype.includes()
TypedArray.prototype.indexOf()
TypedArray.prototype.join()
TypedArray.prototype.keys()
TypedArray.prototype.lastIndexOf()
TypedArray.prototype.map()
TypedArray.prototype.reduce()
TypedArray.prototype.reduceRight()
TypedArray.prototype.reverse()
TypedArray.prototype.set()
TypedArray.prototype.slice()
TypedArray.prototype.some()
TypedArray.prototype.sort()
TypedArray.prototype.subarray()
TypedArray.prototype.toLocaleString()
TypedArray.prototype.toString()
TypedArray.prototype.values()
TypedArray.prototype[@@iterator]()
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()