DataView.prototype.getBigInt64()

Baseline 已廣泛支援

此功能已成熟,並可在多種裝置和瀏覽器版本上執行。自 2021 年 9 月起,所有瀏覽器均已支援此功能。

DataView 例項的 getBigInt64() 方法會讀取此 DataView 中指定位元組偏移量開始的 8 個位元組,並將它們解釋為 64 位有符號整數。沒有對齊約束;多位元組值可以從任何邊界內的偏移量獲取。

試一試

// Create an ArrayBuffer with a size in bytes
const buffer = new ArrayBuffer(16);

// Highest possible BigInt value that fits in a signed 64-bit integer
const max = 2n ** (64n - 1n) - 1n;

const view = new DataView(buffer);
view.setBigInt64(1, max);

console.log(view.getBigInt64(1));
// Expected output: 9223372036854775807n

語法

js
getBigInt64(byteOffset)
getBigInt64(byteOffset, littleEndian)

引數

byteOffset

要從中讀取資料的檢視起始位置的位元組偏移量。

littleEndian 可選

指示資料是以小端序或大端序格式儲存的。如果為 falseundefined,則讀取大端序值。

返回值

一個 BigInt,範圍從 -263 到 263-1(包括兩端)。

異常

RangeError

如果 byteOffset 設定為讀取超出檢視末尾,則會丟擲此錯誤。

示例

使用 getBigInt64()

js
const { buffer } = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
const dataview = new DataView(buffer);
console.log(dataview.getBigInt64(1)); // 72623859790382856n

規範

規範
ECMAScript® 2026 語言規範
# sec-dataview.prototype.getbigint64

瀏覽器相容性

另見