Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. JavaScript
  3. JavaScript リファレンス
  4. 標準組み込みオブジェクト
  5. Uint8Array

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

View in EnglishAlways switch to English

Uint8Array

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

* Some parts of this feature may have varying levels of support.

Uint8Array は型付き配列で、 8 ビット符号なし整数値の配列を表します。初期化データが明示的に与えられなかった場合、中身は0 で初期化されます。生成されると、配列内の要素はそのオブジェクトのメソッドを使用するか、配列の標準的な添字の構文(すなわち、ブラケット記法)を使用するかして参照することができます。

Uint8Array は非公開のTypedArray クラスのサブクラスです。

解説

Uint8Array は、現時点では他の型付き配列に比べて追加のメソッドを持つ唯一のTypedArray サブクラスです。汎用バイト配列という性質のため、任意のバイナリーデータの処理に最も適しています。これは、Uint8Array データの 16 進文字列および base64 文字列への作成、シリアライズ、変更を行う 2 種類のメソッドに対応しています。

コンストラクター

Uint8Array()

新しいUint8Array オブジェクトを生成します。

静的プロパティ

親であるTypedArray から継承した静的プロパティもあります。

Uint8Array.BYTES_PER_ELEMENT

要素の大きさを数値で返します。Uint8Array の場合は1 です。

静的メソッド

親であるTypedArray から継承した静的メソッドもあります。

Uint8Array.fromBase64()

base64 エンコードされた文字列から新しいUint8Array オブジェクトを作成します。

Uint8Array.fromHex()

16 進エンコードされた文字列から新しいUint8Array オブジェクトを作成します。

インスタンスプロパティ

親であるTypedArray から継承したインスタンスプロパティもあります。

これらのプロパティはUint8Array.prototype で定義され、すべてのUint8Array インスタンスで共有されます。

Uint8Array.prototype.BYTES_PER_ELEMENT

要素の大きさを数値で返します。Uint8Array の場合は1 です。

Uint8Array.prototype.constructor

このインスタンスオブジェクトを作成したコンストラクター関数。Uint8Array インスタンスの場合、初期値はUint8Array コンストラクターです。

インスタンスメソッド

親であるTypedArray から継承したインスタンスメソッドもあります。

Uint8Array.prototype.setFromBase64()

このUint8Array オブジェクトに、 base64 エンコードされた文字列から取得したバイト列を格納し、読み込んだバイト数と書き込んだバイト数を示すオブジェクトを返します。

Uint8Array.prototype.setFromHex()

このUint8Array オブジェクトに 16 進エンコードされた文字列から取得取得したバイト列を格納し、読み込んだバイト数と書き込んだバイト数を示すオブジェクトを返します。

Uint8Array.prototype.toBase64()

このUint8Array オブジェクトのデータに基づいて、base64 エンコードされた文字列を返します。

Uint8Array.prototype.toHex()

このUint8Array オブジェクトのデータに基づいて、16 進エンコードされた文字列を返します。

様々な方法でUint8Array を作成

js
// 長さからconst uint8 = new Uint8Array(2);uint8[0] = 42;console.log(uint8[0]); // 42console.log(uint8.length); // 2console.log(uint8.BYTES_PER_ELEMENT); // 1// 配列からconst x = new Uint8Array([21, 31]);console.log(x[1]); // 31// 他の TypedArray からconst y = new Uint8Array(x);console.log(y[0]); // 21// ArrayBuffer からconst buffer = new ArrayBuffer(8);const z = new Uint8Array(buffer, 1, 4);console.log(z.byteOffset); // 1// 反復可能オブジェクトからconst iterable = (function* () {  yield* [1, 2, 3];})();const uint8FromIterable = new Uint8Array(iterable);console.log(uint8FromIterable);// Uint8Array [1, 2, 3]

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-typedarray-objects

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp