Uint16Array
Creates a new Uint16Array typed array representing an array of 16-bit unsigned integers (range 0 to 65535)
Syntax
new Uint16Array(length) or new Uint16Array(buffer, byteOffset?, length?)Parameters
| Parameter | Type | Description |
|---|---|---|
| length | number | ArrayBuffer | ArrayLike<number> | Array length, buffer, or array-like source |
Return Value
A new Uint16Array instance
Examples
const arr = new Uint16Array(3)
arr[0] = 65535
console.log(arr) // Uint16Array [65535, 0, 0]const arr = new Uint16Array([256, 512, 1024])
console.log(arr.byteLength) // 6 (3 * 2 bytes)const buffer = new ArrayBuffer(8)
const u16 = new Uint16Array(buffer)
u16[0] = 0xFFFF
console.log(u16[0]) // 65535Understanding Uint16Array
The Uint16Array method in JavaScript creates a new Uint16Array typed array representing an array of 16-bit unsigned integers (range 0 to 65535). It belongs to the TypedArray object and is one of the most widely used methods for working with typedarray values in modern JavaScript and TypeScript applications.
The method signature is new Uint16Array(length) or new Uint16Array(buffer, byteOffset?, length?). It accepts 1 parameter: length. When called, it returns a new uint16array instance. Understanding when and how to use Uint16Array() helps you write more expressive, readable code.
Common use cases for Uint16Array include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like int16array-constructor, uint8array-constructor, uint32array-constructor, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Uint16Array is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Int16ArrayCreates a new Int16Array typed array representing an array of 16-bit signed integers (range -32768 to 32767)
Uint8ArrayCreates a new Uint8Array typed array representing an array of 8-bit unsigned integers initialized to zero
Uint32ArrayCreates a new Uint32Array typed array representing an array of 32-bit unsigned integers
More TypedArray Methods
Other methods in the TypedArray object
Related Tools
More TypedArray Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.