このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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);
// 予想される結果: BigInt64Array [6118793953620967n, 1881938909131133n, 1898875537769492n]

console.log(bigint64[2]);
// 予想される結果: 1898875537769492n

console.log("配列の長さ:", bigint64.length);
// 予想される結果: 配列の長さ: 3

console.log("配列のバイト長:", bigint64.byteLength);
// 予想される結果: 配列のバイト長: 24

console.log("配列のバイトオフセット:", bigint64.byteOffset);
// 予想される結果: 配列のバイトオフセット: 0

bigint64.set([100n, 200n], 1);
console.log(bigint64);
// 予想される結果: 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
// 長さから
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

// 配列から
const x = new BigInt64Array([21n, 31n]);
console.log(x[1]); // 31n

// 他の TypedArray から
const y = new BigInt64Array(x);
console.log(y[0]); // 21n

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

// 反復可能オブジェクトから
const iterable = (function* () {
  yield* [1n, 2n, 3n];
})();
const bigint64FromIterable = new BigInt64Array(iterable);
console.log(bigint64FromIterable);
// BigInt64Array [1n, 2n, 3n]

仕様書

仕様書
ECMAScript® 2027 Language Specification
# sec-typedarray-objects

ブラウザーの互換性

関連情報