TypedArray

Float32Array

Creates a new Float32Array typed array representing an array of 32-bit IEEE floating point numbers

Syntax

JavaScript
new Float32Array(length) or new Float32Array(buffer, byteOffset?, length?)

Parameters

ParameterTypeDescription
lengthnumber | ArrayBuffer | ArrayLike<number>Array length, buffer, or array-like source

Return Value

A new Float32Array instance

Examples

Basic Usage
const arr = new Float32Array([1.5, 2.7, 3.14])
console.log(arr) // Float32Array [1.5, 2.700000047683716, 3.140000104904175]
Practical Example
const vertices = new Float32Array([
  -1.0, -1.0, 0.0,
   1.0, -1.0, 0.0,
   0.0,  1.0, 0.0
])
console.log('Triangle vertices:', vertices.length / 3)
Advanced Usage
function normalize(arr: Float32Array): Float32Array {
  const max = arr.reduce((a, b) => Math.max(a, b), -Infinity)
  const min = arr.reduce((a, b) => Math.min(a, b), Infinity)
  return arr.map(v => (v - min) / (max - min)) as Float32Array
}

Understanding Float32Array

The Float32Array method in JavaScript creates a new Float32Array typed array representing an array of 32-bit IEEE floating point numbers. It belongs to the TypedArray object and is one of the most widely used methods for working with typedarray values in modern JavaScript and TypeScript applications.

The method signature is new Float32Array(length) or new Float32Array(buffer, byteOffset?, length?). It accepts 1 parameter: length. When called, it returns a new float32array instance. Understanding when and how to use Float32Array() helps you write more expressive, readable code.

Common use cases for Float32Array include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like float64array-constructor, uint32array-constructor, arraybuffer-constructor, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Float32Array is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More TypedArray Methods

Other methods in the TypedArray object

Related Tools

More TypedArray Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.