このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
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月.
Uint8Array() コンストラクターは、Uint8Array オブジェクトを作成します。初期化データが明示的に指定されていない場合、コンテンツは0 に初期化されます。
In this article
構文
js
new Uint8Array()new Uint8Array(length)new Uint8Array(typedArray)new Uint8Array(object)new Uint8Array(buffer)new Uint8Array(buffer, byteOffset)new Uint8Array(buffer, byteOffset, length)引数
TypedArray を参照してください。
例外
TypedArray を参照してください。
例
>様々な方法による 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// 他の型付き配列から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-constructors> |