The Javascript Uint8ClampedArray 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()
.
Uint8ClampedArray.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 Uint8ClampedArray([2, 5, 8, 1, 4]).some(isBiggerThan10); // false console.log(a); a = new Uint8ClampedArray([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 Uint8ClampedArray([2, 5, 8, 1, 4]).some(elem => elem > 10); // false console.log(a);//from w w w.ja v a2s .co m a = new Uint8ClampedArray([12, 5, 8, 1, 4]).some(elem => elem > 10); // true console.log(a);