Javascript BigUint64Array every()

Introduction

The Javascript BigUint64Array every() method tests whether all elements in the typed array pass the provided function.

This method works the same as Array.prototype.every().

BigUint64Array.every(callback[, thisArg])
Parameter
Optional
Meaning
callback




Required




Function to test for each element
Taking three arguments:
currentValue - The current element being processed.
index - the index of the current element.
array - typed array itself.
thisArg
Optional.
Value to use as this when executing callback.

It returns true if the callback function returns a truthy value for every array element; otherwise, false.

every() does not mutate the typed array on which it is called.

The following example tests whether all elements in the typed array are bigger than 10.

function isBigEnough(element, index, array) {
  return element >= 10;
}
let a = new BigUint64Array([12n, 5n, 8n, 130n, 44n]).every(isBigEnough);   // false
console.log(a);/*w w w .j a v  a  2 s. co  m*/
a = new BigUint64Array([12n, 5n, 8n, 130n, 44n]).every(isBigEnough); // true
console.log(a);

Testing typed array elements using arrow functions

Arrow functions provide a shorter syntax for the same test.

let a = new BigUint64Array([12n, 5n, 8n, 130n, 44n]).every(elem => elem >= 10); // false
console.log(a);
new BigUint64Array([12n, 5n, 8n, 130n, 44n]).every(elem => elem >= 10); // true
console.log(a);



PreviousNext

Related