This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

TypedArray.of()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2016년 9월⁩.

정적 메서드 **TypedArray.of()**는 다양한 수의 인자로부터 새로운 형식화 배열를 생성합니다. 이 메서드는 Array.of()와 거의 동일합니다.

시도해 보기

const int16array = Int16Array.of("10", "20", "30", "40", "50");

console.log(int16array);
// Expected output: Int16Array [10, 20, 30, 40, 50]

구문

js
TypedArray.of()
TypedArray.of(element1)
TypedArray.of(element1, element2)
TypedArray.of(element1, element2, /* …, */ elementN)

TypedArray는 아래 중 하나입니다.

매개변수

element1, …, elementN

형식화 배열을 생성할 때 사용할 요소

반환 값

새로운 TypedArray 인스턴스.

설명

보다 자세한 설명은 Array.of()을 참고하시기 바랍니다. Array.of()TypedArray.of()는 약간의 미묘한 차이가 있습니다.

  • TypedArray.of()에 전달된 this 값이 생성자가 아닌 경우 TypedArray.from()TypeError를 발생시키고, Array.of()는 기본적으로 새 Array를 생성합니다.
  • TypedArray.of()[[Set]]를 사용하는 반면 Array.of()[[DefineOwnProperty]]를 사용합니다. 따라서 Proxy 객체로 작업할 때 handler.set()을 호출하여 handler.defineProperty()가 아닌 새 요소를 생성합니다.

예제

of() 사용하기

js
Uint8Array.of(1); // Uint8Array [ 1 ]
Int8Array.of("1", "2", "3"); // Int8Array [ 1, 2, 3 ]
Float32Array.of(1, 2, 3); // Float32Array [ 1, 2, 3 ]
Int16Array.of(undefined); // Int16Array [ 0 ]

명세서

Specification
ECMAScript® 2026 Language Specification
# sec-%typedarray%.of

브라우저 호환성

같이 보기