DataView.prototype.setUint16()
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.
setUint16()
メソッドは、符号なし 16 ビット整数 (unsigned short) 値を DataView
の指定されたバイト単位のオフセットの位置に格納します。
試してみましょう
// Create an ArrayBuffer with a size in bytes
const buffer = new ArrayBuffer(16);
const view = new DataView(buffer);
view.setUint16(1, 65535); // Max unsigned 16-bit integer
console.log(view.getUint16(1));
// Expected output: 65535
構文
dataview.setUint16(byteOffset, value [, littleEndian])
引数
byteOffset
-
ビューの先頭からのバイト単位のオフセットで、データを格納する位置です。
value
-
設定する値です。
littleEndian
-
省略可 16 ビット整数をリトルエンディアンとビッグエンディアンのどちらの形式で格納するかを表します。
false
またはundefined
の場合、ビッグエンディアン値が書き込まれます。
返値
発生するエラー
RangeError
-
byteOffset
がビューの末尾を超えて格納するように設定されている場合に発生します。
例
setUint16 メソッドの使用
js
var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.setUint16(1, 3);
dataview.getUint16(1); // 3
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-dataview.prototype.setuint16 |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
setUint16 |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.