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 a required parameter.
index: It represents the current element’s index in the array. It is an optional parameter.
arr: It means the array. It is an optional parameter.
thisValue: It means this for the current function. “undefined” will be passed if this parameter is empty. It is an optional parameter.
Returns:
It returns 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>
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>