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