Uint32Array() constructor

Uint32Array 형식화 배열(TypedArray)의 생성자는 플랫폼의 바이트 순서를 따르는 32비트 부호 없는 정수 배열을 생성합니다. 바이트 순서를 제어해야 하는 경우 대신 DataView를 사용합니다. 배열의 내용은 0으로 초기화됩니다. 배열이 생성되면 객체의 메서드를 사용하거나 표준 배열 인덱스 구문(즉, 대괄호 표기법 사용)을 사용하여 배열의 요소를 참조할 수 있습니다.

구문

js
new Uint32Array()
new Uint32Array(length)
new Uint32Array(typedArray)
new Uint32Array(object)

new Uint32Array(buffer)
new Uint32Array(buffer, byteOffset)
new Uint32Array(buffer, byteOffset, length)

Note: Uint32Array()는 오직 new로만 생성할 수 있습니다. new 없이 호출을 시도하면 TypeError 예외가 발생합니다.

매개 변수

TypedArray를 참고하세요.

예외

TypedArray를 참고하세요.

예제

Uint32Array을 생성하기 위한 각기 다른 여러 방법

js
// 길이로부터 생성
const uint32 = new Uint32Array(2);
uint32[0] = 42;
console.log(uint32[0]); // 42
console.log(uint32.length); // 2
console.log(uint32.BYTES_PER_ELEMENT); // 4

// 배열로부터
const x = new Uint32Array([21, 31]);
console.log(x[1]); // 31

// 다른 TypedArray로부터
const y = new Uint32Array(x);
console.log(y[0]); // 21

// ArrayBuffer로부터
const buffer = new ArrayBuffer(32);
const z = new Uint32Array(buffer, 4, 4);
console.log(z.byteOffset); // 4

// 순회로부터
const iterable = (function* () {
  yield* [1, 2, 3];
})();
const uint32FromIterable = new Uint32Array(iterable);
console.log(uint32FromIterable);
// Uint32Array [1, 2, 3]

명세

Specification
ECMAScript Language Specification
# sec-typedarray-constructors

브라우저 호환성

BCD tables only load in the browser

같이 보기