概要
Uint32Array タイプは、32 ビット符号なし整数値の配列を表します。各要素のバイトオーダーはプラットフォームに依存します。もしコントロールしたい場合は代わりに DataView を使って下さい。各要素は 0 で初期化されます。生成された Uint32Array オブジェクトのメソッドあるいは配列のような表記法 ("[]") を用いて、要素を参照できます。
構文
new Uint32Array(length); new Uint32Array(typedArray); new Uint32Array(object); new Uint32Array(buffer [, byteOffset [, length]]);
コンストラクターの構文とパラメーターについての詳しい情報は TypedArray を参照して下さい。
プロパティ
Uint32Array.BYTES_PER_ELEMENT- 要素 1 個あたりのバイト数を返します。
Uint32Arrayの場合は4です。 - Uint32Array.length
値は3になります。実際の長さ (要素数) についてはUint32Array.prototype.lengthを参照して下さい。Uint32Array.name- コンストラクター名を文字列値で返します。
Uint32Arrayの場合、"Uint32Array"です。 Uint32Array.prototype- TypedArray オブジェクトのプロトタイプです。
-
メソッド
Uint32Array.from()- 配列状のオブジェクトやイテレート可能なオブジェクトから、新たな
Uint32Arrayオブジェクトを生成します。Array.from()も確かめて下さい。 Uint32Array.of()- 可変長引数で新しい
Uint32Arrayオブジェクトを生成します。Array.of()も確かめて下さい。
Uint32Array プロトタイプ
すべての Uint32Array オブジェクトは %TypedArray%.prototype を継承しています。
プロパティ
Uint32Array.prototype.constructor- インスタンスのプロトタイプを作る関数を返します。これは、デフォルトで対応する
Uint32Arrayコンストラクターです。 Uint32Array.prototype.buffer読取専用Uint32Arrayオブジェクトによって参照されるArrayBufferを返します。構築時に設定され、読取専用 となります。Uint32Array.prototype.byteLength読取専用ArrayBufferの開始位置からのUint32Arrayオブジェクトの (バイト単位の) 長さを返します。構築時に設定され、読取専用 となります。Uint32Array.prototype.byteOffset読取専用ArrayBufferの開始位置からのUint32Arrayオブジェクトの (バイト単位の) オフセットを返します。構築時に設定され、読取専用 となります。Uint32Array.prototype.length読取専用Uint32Arrayオブジェクト内に保持された要素の数を返します。構築時に設定され、読取専用 となります。-
メソッド
Uint32Array.prototype.copyWithin()- 配列内で一連の配列要素をコピーします。
Array.prototype.copyWithin()も確かめて下さい。 Uint32Array.prototype.entries()- 配列内で各インデックスに対して、キー/バリュー ペアを含む新しい
Array Iteratorを返します。Array.prototype.entries()も確かめて下さい。 Uint32Array.prototype.every()- 配列内のすべての要素が関数によって提供されたテストに合格するかどうかテストを実行します。
Array.prototype.every()も確かめて下さい。 Uint32Array.prototype.fill()- 開始位置から終了位置までの配列のすべての要素を固定値で設定します。
Array.prototype.fill()も確かめて下さい。 Uint32Array.prototype.filter()- 与えられたフィルタリング関数が true を返す配列のすべての要素をもつ新しい配列を生成します。
Array.prototype.filter()も確かめて下さい。 Uint32Array.prototype.find()- 配列要素が与えられたテスト関数を満足したら、配列の値を返します。満足しなかった場合、
undefinedを返します。Array.prototype.find()を確かめて下さい。 Uint32Array.prototype.findIndex()- 配列要素が与えられたテスト関数を満足したら、配列のインデックスを返します。満足しなかった場合、-1 を返します。
Array.prototype.findIndex()も確かめて下さい。 Uint32Array.prototype.forEach()- 配列内の各要素に対する関数を呼び出します。
Array.prototype.forEach()も確かめて下さい。 Uint32Array.prototype.includes()- typed arrayがある要素を含むかどうか判断し、それに応じて、
trueかfalseを返します。Array.prototype.includes()も確かめて下さい。 Uint32Array.prototype.indexOf()- 指定された値に等しい配列内の要素の最初のインデックスを返します。見つからない場合、-1 を返します。
Array.prototype.indexOf()も確かめて下さい。 Uint32Array.prototype.join()- すべての配列要素を文字列に結合します。
Array.prototype.join()も確かめて下さい。 Uint32Array.prototype.keys()- 配列内の各インデックスに対するキーを含む新しい
Array Iteratorを返します。Array.prototype.keys()も確かめて下さい。 Uint32Array.prototype.lastIndexOf()- 指定された値と等しい配列の要素の最後のインデックスを返します。見つからない場合、-1 を返します。
Array.prototype.lastIndexOf()を確かめて下さい。 Uint32Array.prototype.map()- この配列のすべての要素で与えられた関数を呼び出した結果をもつ新しい配列を生成します。
Array.prototype.map()も確かめて下さい。 Uint32Array.prototype.move()未実装TypedArray.prototype.copyWithin()の以前の非標準バージョンUint32Array.prototype.reduce()- アキュムレーターに対して関数を適用し、隣り合う二つのtyped arrayの要素 (左から右へ) は単一の値になります。
Array.prototype.reduce()も確かめて下さい。 Uint32Array.prototype.reduceRight()- アキュムレータに対して関数を適用し、隣り合う二つのtyped arrayの要素 (右から左へ) は単一の値になります。
Array.prototype.reduceRight()を確かめて下さい。 Uint32Array.prototype.reverse()- 配列要素の順番を反転させます — 最初の要素は最後になり、最後の要素は最初になります。
Array.prototype.reverse()も確かめて下さい。 Uint32Array.prototype.set()- 入力値を指定した配列から読み込み、typed array 内に複数の値を格納します。
Uint32Array.prototype.slice()- 配列の一部を取り出して新しい配列を返します。
Array.prototype.slice()も確かめて下さい。 Uint32Array.prototype.some()- ある配列の少なくとも 1 つの要素が与えられたテスト関数を満たした場合に true を返します。
Array.prototype.some()も確かめて下さい。 Uint32Array.prototype.sort()- 配列の要素をソートし、その結果を返します。
Array.prototype.sort()も確かめて下さい。 Uint32Array.prototype.subarray()- 与えられた開始位置と終了位置の要素インデックスの新しい
Uint32Arrayオブジェクトを返します。 Uint32Array.prototype.values()- 配列内で各インデックスに対する値を含む新しい
Array Iteratorオブジェクトを返します。Array.prototype.values()を確かめて下さい。 Uint32Array.prototype.toLocaleString()- 配列と要素を表すローカライズされた文字列を返します。
Array.prototype.toLocaleString()も確かめて下さい。 Uint32Array.prototype.toString()- 配列と要素を表す文字列を返します。
Array.prototype.toString()も確かめて下さい。 Uint32Array.prototype[@@iterator]()- 配列内で各インデックスに対する値を含む新しい
Array Iteratorオブジェクトを返します。
例
// From a length
var uint32 = new Uint32Array(2);
uint32[0] = 42;
console.log(uint32[0]); // 42
console.log(uint32.length); // 2
console.log(uint32.BYTES_PER_ELEMENT); // 4
// From an array
var arr = new Uint32Array([21,31]);
console.log(arr[1]); // 31
// From another TypedArray
var x = new Uint32Array([21, 31]);
var y = new Uint32Array(x);
console.log(y[0]); // 21
// From an ArrayBuffer
var buffer = new ArrayBuffer(16);
var z = new Uint32Array(buffer, 0, 4);
// From an iterable
var iterable = function*(){ yield* [1,2,3]; }();
var uint32 = new Uint32Array(iterable);
// Uint32Array[1, 2, 3]
仕様
| 仕様書 | 策定状況 | コメント |
|---|---|---|
| Typed Array Specification | 廃止された | ECMAScript 2015 で置き換えられました。 |
| ECMAScript 2015 (6th Edition, ECMA-262) TypedArray constructors の定義 |
標準 | ECMA 標準では最初の定義。new 演算子が必要なことが仕様書に含まれました。 |
| ECMAScript Latest Draft (ECMA-262) TypedArray constructors の定義 |
ドラフト |
ブラウザー実装状況
現在、互換性データを可読形式の JSON フォーマットに置き換えているところです。
この互換性一覧は古い形式を使っており、これに含まれるデータの置き換えが済んでいません。
手助けしていただける場合は、こちらから!
| 機能 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| 基本サポート | 7.0 | 4.0 (2) | 10 | 11.6 | 5.1 |
new が必要 |
? | 44 (44) | ? | ? | ? |
| コンストラクター内の Iterable | ? | 52 (52) | ? | ? | ? |
| 機能 | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| 基本サポート | 4.0 | (有) | 4.0 (2) | 10 | 11.6 | 4.2 |
new が必要 |
? | ? | 44.0 (44) | ? | ? | ? |
| コンストラクター内の Iterable | ? | ? | 52.0 (52) | ? | ? | ? |
互換性について
ECMAScript 2015 から、Uint32Array コンストラクターでインスタンスを生成する場合、 new 演算子が必要となります。Uint32Array を new 演算子を使用せずに関数呼び出しした場合、TypeError 例外が投げられるでしょう。
var dv = Uint32Array([1, 2, 3]); // TypeError: calling a builtin Uint32Array constructor // without new is forbidden
var dv = new Uint32Array([1, 2, 3]);