TypedArray.prototype.filter()
TypedArray
实例的 filter()
方法创建给定类型化数组的一部分的副本,过滤为仅给定类型化数组中通过所提供函数实现的测试的元素。该方法与 Array.prototype.filter()
的算法相同。
¥The filter()
method of TypedArray
instances creates a copy of a portion of a given typed array, filtered down to just the elements from the given typed array that pass the test implemented by the provided function. This method has the same algorithm as Array.prototype.filter()
.
Try it
语法
参数
返回值
描述
¥Description
详细信息请参见 Array.prototype.filter()
。此方法不是通用的,只能在类型化数组实例上调用。
¥See Array.prototype.filter()
for more details. This method is not generic and can only be called on typed array instances.
示例
过滤掉所有小值
¥Filtering out all small values
以下示例使用 filter()
创建一个过滤类型数组,其中删除了所有值小于 10 的元素。
¥The following example uses filter()
to create a filtered typed array that has all elements with values less than 10 removed.
function isBigEnough(element, index, array) {
return element >= 10;
}
new Uint8Array([12, 5, 8, 130, 44]).filter(isBigEnough);
// Uint8Array [ 12, 130, 44 ]
规范
Specification |
---|
ECMAScript Language Specification # sec-%typedarray%.prototype.filter |
浏览器兼容性
BCD tables only load in the browser