Javascript Uint8ClampedArray lastIndexOf()

Introduction

The Javascript Uint8ClampedArray 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().

Uint8ClampedArray.lastIndexOf(searchElement[, fromIndex = Uint8ClampedArray.length])
Parameter Optional Meaning
searchElement Required Element to locate in the typed array.
fromIndex OptionalThe 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 Uint8ClampedArray([2, 5, 9, 2]);
let a = uint8.lastIndexOf(2);     
console.log(a);/*from w  w  w  .  java  2s .  c  om*/
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);



PreviousNext

Related