ArrayBuffer.isView()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

尝试一下

语法

js
ArrayBuffer.isView(value)

参数

value

要检查的值。

返回值

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

示例

使用 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

浏览器兼容性

BCD tables only load in the browser

参见