TypedArray findIndex() JavaScript

The Javascript TypedArray findIndex() method retrieves the index of the first element that completes the given test in the array. It will return -1 if no part satisfies the given condition.

Syntax:

array.findIndex(function(value, index, arr) thisValue) 

Parameters:
value: It represents the current element’s value.
index: It represents the index position of the current element.
arr: It represents the array.
thisValue: It represents this argument for the function.

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(i)
{ return i>= "O"; }
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];
var gems =Jewels.findIndex(func);
document.write(gems);
</script>
</body>
</html>

Example 2:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function isNegative(element, index, array) {
return element < 0;
}
const testArray = new Int8Array([45, -26, 56, -23, 78]);
document.write(testArray.findIndex(isNegative));
</script>
</body>
</html>