The Javascript Uint8Array lastIndexOf()
method returns the last index for a given element.
It returns -1 if not found.
The typed array is searched backwards, starting at fromIndex
.
This method works the same as Array.prototype.lastIndexOf()
.
Uint8Array.lastIndexOf(searchElement[, fromIndex = Uint8Array.length])
Parameter | Optional | Meaning |
---|---|---|
searchElement | Required | Element to locate in the typed array. |
fromIndex | Optional | The index at which to start searching backwards. |
fromIndex
defaults to the typed array's length.
If the fromIndex
is greater than or equal to the array.length, the whole typed array will be searched.
If negative, uses array.length+fromIndex
.
lastIndexOf()
uses strict equality (=== operator).
var uint8 = new Uint8Array([2, 5, 9, 2]); let a = uint8.lastIndexOf(2); console.log(a);// www. j av a 2 s. c o m a = uint8.lastIndexOf(7); console.log(a); a = uint8.lastIndexOf(2, 3); console.log(a); a = uint8.lastIndexOf(2, 2); console.log(a); a = uint8.lastIndexOf(2, -2); console.log(a); a = uint8.lastIndexOf(2, -1); console.log(a);