TypedArray indexof() JavaScript

The Javascript TypedArray index () method finds 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 means the index position to start the search. The default is 0. It is an optional parameter.

Returns:
It returns the index of the first element that satisfies the given test in the array. It will return -1 if no part satisfies 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>

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>