HTML: Markup language
CSS: Styling language
JavaScript: Scripting language
Web APIs: Programming interfaces
All web technology
Learn web development
Discover our tools
Get to know MDN better
此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。
View in English Always switch to English
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Uint16Array 类型化数组表示 16 位无符号整数,按平台字节顺序排列。如果需要控制字节顺序,请使用 DataView 代替。内容被初始化为 0。建立后,就可以使用对象的方法或使用标准数组索引语法(即使用括号表示法)引用数组中的元素。
Uint16Array
Uint16Array()
创建一个新的 Uint16Array 对象。
Uint16Array.BYTES_PER_ELEMENT
返回元素大小的数值。在 Uint16Array 情况下为 2。
2
Uint16Array.from()
从类数组或可迭代对象创建一个新的 Uint16Array。可参阅 Array.from()。
Array.from()
Uint16Array.of()
创建一个新的具有可变参数数目的 Uint16Array。可参阅 Array.of()。
Array.of()
还从其父接口 TypedArray 继承实例属性。
TypedArray
Uint16Array.prototype.buffer
返回 Uint16Array 在构造时固定引用的 ArrayBuffer。因此是只读的。
ArrayBuffer
Uint16Array.prototype.byteLength
返回 Uint16Array 从 ArrayBuffer 开始的长度(以字节为单位)。在构建时固定,因此是只读的。
Uint16Array.prototype.byteOffset
返回 Uint16Array 从 ArrayBuffer 开始的偏移量(以字节为单位)。在构建时固定,因此是只读的。
Uint16Array.prototype.length
返回 Uint16Array 中包含的元素数量。在构建时固定,因此是只读的。
从其父接口 TypedArray 继承实例方法。
// 长度 var uint16 = new Uint16Array(2); uint16[0] = 42; console.log(uint16[0]); // 42 console.log(uint16.length); // 2 console.log(uint16.BYTES_PER_ELEMENT); // 2 // 数组 var arr = new Uint16Array([21, 31]); console.log(arr[1]); // 31 // 另一个类型数组 var x = new Uint16Array([21, 31]); var y = new Uint16Array(x); console.log(y[0]); // 21 // 一个 ArrayBuffer var buffer = new ArrayBuffer(8); var z = new Uint16Array(buffer, 0, 4); // 可迭代 var iterable = (function* () { yield* [1, 2, 3]; })(); var uint16 = new Uint16Array(iterable); // Uint16Array[1, 2, 3]
Enable JavaScript to view this browser compatibility table.
core-js
DataView