The Javascript Int8Array some()
method if some element in the typed array passes the test implemented by the provided function.
This method works the same as Array.prototype.some()
.
Int8Array.some(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 being processed.array - the 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 any array element; otherwise, false.
Testing size of all typed array elements
The following example tests whether any element in the typed array is bigger than 10.
function isBiggerThan10(element, index, array) { return element > 10; } let a = new Int8Array([2, 5, 8, 1, 4]).some(isBiggerThan10); // false console.log(a); a = new Int8Array([12, 5, 8, 1, 4]).some(isBiggerThan10); // true console.log(a);
Testing typed array elements using arrow functions
Arrow functions provide a shorter syntax for the same test.
let a = new Int8Array([2, 5, 8, 1, 4]).some(elem => elem > 10); // false console.log(a);/*from w ww . jav a 2 s. c o m*/ a = new Int8Array([12, 5, 8, 1, 4]).some(elem => elem > 10); // true console.log(a);