Javascript Uint16Array indexOf()

Introduction

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

Uint16Array.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 Uint16Array([2, 5, 9]);
let a = uint8.indexOf(2);     
console.log(a);//ww w . ja  va 2  s.  c o  m
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