Float16Array() 생성자
Baseline 2025Newly available
Since April 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Float16Array()
생성자는 Float16Array
객체를 생성합니다. 명시적으로 초기 값이 주어지지 않으면 내용은 모두 0
으로 초기화됩니다.
구문
매개변수
TypedArray
를 참고하세요.
예외
TypedArray
를 참고하세요.
예제
Float16Array를 생성하기 위한 각기 다른 여러 방법
js
// 길이로부터 생성
const float16 = new Float16Array(2);
float16[0] = 42;
console.log(float16[0]); // 42
console.log(float16.length); // 2
console.log(float16.BYTES_PER_ELEMENT); // 2
// 배열로부터 생성
const x = new Float16Array([21, 31]);
console.log(x[1]); // 31
// 다른 TypedArray로부터 생성
const y = new Float16Array(x);
console.log(y[0]); // 21
// ArrayBuffer로부터 생성
const buffer = new ArrayBuffer(32);
const z = new Float16Array(buffer, 4, 4);
console.log(z.byteOffset); // 4
// 순회로부터 생성
const iterable = (function* () {
yield* [1, 2, 3];
})();
const float16FromIterable = new Float16Array(iterable);
console.log(float16FromIterable);
// Float16Array [1, 2, 3]
명세서
Specification |
---|
ECMAScript® 2026 Language Specification # sec-typedarray-constructors |