TypedArray every() JavaScript JS

The Javascript TypedArray every() method is used to check whether all the elements of an array satisfy the given condition or not.

Syntax:

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

Parameters:
value: It represents the current element’s value. It is required parameter.
index: It represents the current element’s index in the array. It is optional parameter.
arr: It represents the array. It is optional parameter.
thisValue: It represents this for the current function. “undefined” will be passed if this parameter is empty. It is optional parameter.

Returns:
It return true if all array elements satisfy the specific condition implemented by the argument function.

Example 1:

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

Output:

true

Example 2:

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

Output:

false
Please Share