ArrayBuffer.isView()

ArrayBuffer.isView() 静态方法确定传递的值是否是 ArrayBuffer 视图之一,例如 类型化数组对象DataView

¥The ArrayBuffer.isView() static method determines whether the passed value is one of the ArrayBuffer views, such as typed array objects or a DataView.

Try it

语法

¥Syntax

js
ArrayBuffer.isView(value)

参数

¥Parameters

value

要检查的值。

返回值

¥Return value

true 如果给定参数是 ArrayBuffer 视图之一;否则,false

¥true if the given argument is one of the ArrayBuffer views; otherwise, false.

示例

¥Examples

使用 isView

¥Using isView

js
ArrayBuffer.isView(); // false
ArrayBuffer.isView([]); // false
ArrayBuffer.isView({}); // false
ArrayBuffer.isView(null); // false
ArrayBuffer.isView(undefined); // false
ArrayBuffer.isView(new ArrayBuffer(10)); // false

ArrayBuffer.isView(new Uint8Array()); // true
ArrayBuffer.isView(new Float32Array()); // true
ArrayBuffer.isView(new Int8Array(10).subarray(0, 3)); // true

const buffer = new ArrayBuffer(2);
const dv = new DataView(buffer);
ArrayBuffer.isView(dv); // true

规范

Specification
ECMAScript Language Specification
# sec-arraybuffer.isview

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also