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.
TheFloat16Array typed array represents an array of 16-bit floating point numbers in the platform byte order. If control over byte order is needed, useDataView instead. The contents are initialized to0 unless initialization data is explicitly provided. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation).
Float16Array is a subclass of the hiddenTypedArray class.
Note:Float16 support is not universal, both in the JavaScript API and the underlying CPU architecture. Using it may result in slower performance on some platforms. It is intended for interacting with highly optimized and performance-sensitive systems such asfloat-backed canvases, WebGPU, WebGL, and deep learning models includingstable diffusion.
In this article
Constructor
Float16Array()Creates a new
Float16Arrayobject.
Static properties
Also inherits static properties from its parentTypedArray.
Float16Array.BYTES_PER_ELEMENTReturns a number value of the element size.
2in the case ofFloat16Array.
Static methods
Inherits static methods from its parentTypedArray.
Instance properties
Also inherits instance properties from its parentTypedArray.
These properties are defined onFloat16Array.prototype and shared by allFloat16Array instances.
Float16Array.prototype.BYTES_PER_ELEMENTReturns a number value of the element size.
2in the case of aFloat16Array.Float16Array.prototype.constructorThe constructor function that created the instance object. For
Float16Arrayinstances, the initial value is theFloat16Arrayconstructor.
Instance methods
Inherits instance methods from its parentTypedArray.
Examples
>Different ways to create a Float16Array
// From a lengthconst float16 = new Float16Array(2);float16[0] = 42;console.log(float16[0]); // 42console.log(float16.length); // 2console.log(float16.BYTES_PER_ELEMENT); // 2// From an arrayconst x = new Float16Array([21, 31]);console.log(x[1]); // 31// From another TypedArrayconst y = new Float16Array(x);console.log(y[0]); // 21// From an ArrayBufferconst buffer = new ArrayBuffer(32);const z = new Float16Array(buffer, 4, 4);console.log(z.byteOffset); // 4// From an iterableconst iterable = (function* () { yield* [1, 2, 3];})();const float16FromIterable = new Float16Array(iterable);console.log(float16FromIterable);// Float16Array [1, 2, 3]Specifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-float16array> |