TypedArray.prototype.includes()
TypedArray
实例的 includes()
方法确定类型化数组的条目中是否包含某个值,并根据需要返回 true
或 false
。该方法与 Array.prototype.includes()
的算法相同。
¥The includes()
method of TypedArray
instances determines whether a typed array includes a certain value among its entries, returning true
or false
as appropriate. This method has the same algorithm as Array.prototype.includes()
.
Try it
语法
参数
返回值
描述
¥Description
详细信息请参见 Array.prototype.includes()
。此方法不是通用的,只能在类型化数组实例上调用。
¥See Array.prototype.includes()
for more details. This method is not generic and can only be called on typed array instances.
示例
使用包含()
¥Using includes()
js
const uint8 = new Uint8Array([1, 2, 3]);
uint8.includes(2); // true
uint8.includes(4); // false
uint8.includes(3, 3); // false
// NaN handling (only true for Float32 and Float64)
new Uint8Array([NaN]).includes(NaN); // false, since the NaN passed to the constructor gets converted to 0
new Float32Array([NaN]).includes(NaN); // true;
new Float64Array([NaN]).includes(NaN); // true;
规范
Specification |
---|
ECMAScript Language Specification # sec-%typedarray%.prototype.includes |
浏览器兼容性
BCD tables only load in the browser