DataView.prototype.setInt8()
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.
setInt8()
メソッドは、符号付き 8 ビット整数 (byte) 値を DataView
の指定されたバイト単位のオフセットの位置に格納します。
試してみましょう
// Create an ArrayBuffer with a size in bytes
const buffer = new ArrayBuffer(16);
const view = new DataView(buffer);
view.setInt8(1, 127); // Max signed 8-bit integer
console.log(view.getInt8(1));
// Expected output: 127
構文
dataview.setInt8(byteOffset, value)
引数
byteOffset
-
ビューの先頭からのバイト単位のオフセットで、データを格納する位置です。
value
-
設定する値です。
返値
発生するエラー
RangeError
-
byteOffset
がビューの末尾を超えて格納するように設定されている場合に発生します。
例
setInt8 メソッドの使用
js
var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.setInt8(1, 3);
dataview.getInt8(1); // 3
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-dataview.prototype.setint8 |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
setInt8 |
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.