The Javascript BigInt64Array every()
method tests whether all elements in the typed array pass the provided function.
This method works the same as Array.prototype.every()
.
BigInt64Array.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 BigInt64Array([12n, 5n, 8n, 130n, 44n]).every(isBigEnough); // false console.log(a);//from ww w. j a va 2 s. c o m a = new BigInt64Array([12n, 54n, 18n, 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 BigInt64Array([12n, 5n, 8n, 130n, 44n]).every(elem => elem >= 10); // false console.log(a); new BigInt64Array([12n, 54n, 18n, 130n, 44n]).every(elem => elem >= 10); // true console.log(a);