TypedArray indexof() JavaScript

The Javascript TypedArray indexof() method find the index of the element provided as the argument to the function.

Syntax:

Array.indexOf(value, start) 

Parameters:
value: It represents the current element’s value.
start: It represents the index position to start the search. Default is 0. It is optional parameter.

Returns:
It returns index of the first element that satisfy the given test in the array. It will return -1, if no element satisfy the given condition.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">  
function func() {  
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];
document.write(Jewels.indexOf("SILVER"));  
}  
func();  
</script>
</body>
</html>

Output:

3

Example 2:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript"> 
const testArray = new Uint8Array([45, 26, 23, 12, 67]);
 
document.write(testArray.indexOf(26));
document.write("</br>");
 
document.write(testArray.indexOf(26, 3));
document.write("</br>");
 
document.write(testArray.indexOf(11));
 
</script>
</body>
</html>

Output:

1
-1
-1
Please Share