BigInt64Array

Baseline 已廣泛支援

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

BigInt64Array 型別陣列表示一個包含平臺位元組序中的 64 位有符號整數的陣列。如果需要控制位元組序,請改用 DataView。除非顯式提供初始化資料,否則其內容將初始化為 0n。一旦建立,您就可以使用該物件的方法或使用標準的陣列索引語法(即使用方括號表示法)來引用陣列中的元素。

BigInt64Array 是隱藏的 TypedArray 類的子類。

試一試

const buffer = new ArrayBuffer(24);
const bigint64 = new BigInt64Array(buffer);
bigint64[0] = 5886014448488689n;
bigint64[1] = 1881938909131133n;
bigint64[2] = 1898875537769492n;

bigint64[0] = 6118793953620967n;
console.log(bigint64);
// Expected Output: BigInt64Array [6118793953620967n, 1881938909131133n, 1898875537769492n]

console.log(bigint64[2]);
// Expected Output: 1898875537769492n

console.log("Array length:", bigint64.length);
// Expected Output: Array length: 3

console.log("Array byte length:", bigint64.byteLength);
// Expected Output: Array byte length: 24

console.log("Array byte offset:", bigint64.byteOffset);
// Expected Output: Array byte offset: 0

bigint64.set([100n, 200n], 1);
console.log(bigint64);
// Expected Output: BigInt64Array [6118793953620967n, 100n, 200n]

建構函式

BigInt64Array()

建立一個新的 BigInt64Array 物件。

靜態屬性

也繼承了其父類 TypedArray 的靜態屬性.

BigInt64Array.BYTES_PER_ELEMENT

返回一個表示元素大小的數值。對於 BigInt64Array,此值為 8

靜態方法

繼承了其父類 TypedArray 的靜態方法.

例項屬性

也繼承了其父類 TypedArray 的例項屬性.

這些屬性定義在 BigInt64Array.prototype 上,並由所有 BigInt64Array 例項共享。

BigInt64Array.prototype.BYTES_PER_ELEMENT

返回一個表示元素大小的數值。對於 BigInt64Array,此值為 8

BigInt64Array.prototype.constructor

建立例項物件的建構函式。對於 BigInt64Array 例項,初始值為 BigInt64Array 建構函式。

例項方法

繼承了其父類 TypedArray 的例項方法.

示例

建立 BigInt64Array 的不同方法

js
// From a length
const bigint64 = new BigInt64Array(2);
bigint64[0] = 42n;
console.log(bigint64[0]); // 42n
console.log(bigint64.length); // 2
console.log(bigint64.BYTES_PER_ELEMENT); // 8

// From an array
const x = new BigInt64Array([21n, 31n]);
console.log(x[1]); // 31n

// From another TypedArray
const y = new BigInt64Array(x);
console.log(y[0]); // 21n

// From an ArrayBuffer
const buffer = new ArrayBuffer(64);
const z = new BigInt64Array(buffer, 8, 4);
console.log(z.byteOffset); // 8

// From an iterable
const iterable = (function* () {
  yield* [1n, 2n, 3n];
})();
const bigint64FromIterable = new BigInt64Array(iterable);
console.log(bigint64FromIterable);
// BigInt64Array [1n, 2n, 3n]

規範

規範
ECMAScript® 2026 語言規範
# sec-typedarray-objects

瀏覽器相容性

另見