TypedArray.prototype.some()
TypedArray
实例的 some()
方法测试类型化数组中的至少一个元素是否通过所提供函数实现的测试。如果在类型化数组中找到所提供的函数返回 true 的元素,则返回 true;否则返回 false。它不会修改类型化数组。该方法与 Array.prototype.some()
的算法相同。
¥The some()
method of TypedArray
instances tests whether at least one element in the typed array passes the test implemented by the provided function. It returns true if, in the typed array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the typed array. This method has the same algorithm as Array.prototype.some()
.
Try it
语法
参数
返回值
描述
¥Description
详细信息请参见 Array.prototype.some()
。此方法不是通用的,只能在类型化数组实例上调用。
¥See Array.prototype.some()
for more details. This method is not generic and can only be called on typed array instances.
示例
测试所有类型数组元素的大小
¥Testing size of all typed array elements
以下示例测试类型化数组中的任何元素是否大于 10。
¥The following example tests whether any element in the typed array is bigger than 10.
function isBiggerThan10(element, index, array) {
return element > 10;
}
new Uint8Array([2, 5, 8, 1, 4]).some(isBiggerThan10); // false
new Uint8Array([12, 5, 8, 1, 4]).some(isBiggerThan10); // true
规范
Specification |
---|
ECMAScript Language Specification # sec-%typedarray%.prototype.some |
浏览器兼容性
BCD tables only load in the browser