Javascript Int32Array lastIndexOf()

Introduction

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

Int32Array.lastIndexOf(searchElement[, fromIndex = Int32Array.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 Int32Array([2, 5, 9, 2]);
let a = uint8.lastIndexOf(2);     
console.log(a);// ww w  .j a v  a  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