TypedArray find() JavaScript

The Javascript TypedArray find() method retrieves the value of the first element in the array that satisfies the specific condition.

Syntax:

array.find(function(value, index, array))  

Parameters:
value: It represents the current element’s value.
index: It represents the index position of current element.
array: It represents the array.

Returns:
It returns the first array element that satisfy the specified condition, otherwise returns undefined.

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.find(func);   
document.write(gems);  
</script>
</body>
</html>

Output:

PLATINUM

Example 2:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">  
function isNegative(element, index, array) {
  return element < 0;
}
 
const testArray = new Int8Array([16, 40, -68, -67, -50]);
 
document.write(testArray.find(isNegative));
 
</script>
</body>
</html>

Output:

-68
Please Share