Standard built-ins

DataView.prototype.setUint16()

Try the free JavaScript compiler

Writes an unsigned 16-bit field using the selected byte order; bounds are checked.

Formal Syntax & Structure

javascript syntaxjavascript
view.setUint16(byteOffset, value, littleEndian)

Parameters & Attributes

NameTypeDescription
byteOffsetnumberField offset in bytes.
valuenumberNumeric field value.
littleEndianbooleanUse little-endian when true.

Return Value

undefined

Writes an unsigned 16-bit field using the selected byte order; bounds are checked.

Working Example

Example Snippetjavascript
(async () => {const b=new ArrayBuffer(3);new DataView(b).setUint16(1,258,true);console.log(JSON.stringify([...new Uint8Array(b)]));})()
JavaScript Reference