Javascript Uint8ClampedArray indexOf()

Introduction

The Javascript Uint8ClampedArray indexOf() method returns the first index for a given element, or -1 if it is not present.

This method works the same as Array.prototype.indexOf().

Uint8ClampedArray.indexOf(searchElement[, fromIndex = 0])
Parameter Optional Meaning
searchElementRequiredElement to find in the typed array.
fromIndex Optional The index to start the search at.

If the fromIndex is greater than or equal to the typed array's length, -1 is returned.

If the fromIndex is a negative number, it is array.length+ fromIndex.

indexOf() uses strict equality (=== operator).

var uint8 = new Uint8ClampedArray([2, 5, 9]);
let a = uint8.indexOf(2);     
console.log(a);//www  . j a v a 2  s. c  om
a = uint8.indexOf(7);     
console.log(a);
a = uint8.indexOf(9, 2);  
console.log(a);
a = uint8.indexOf(2, -1); 
console.log(a);
a = uint8.indexOf(2, -3); 
console.log(a);



PreviousNext

Related