Summary
The Float32Array typed array represents an array of 32-bit floating point numbers (corresponding to the C float data type) in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. 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).
Syntax
Float32Array(length); Float32Array(typedArray); Float32Array(object); Float32Array(buffer [, byteOffset [, length]]);
For more information about the constructor syntax and the parameters, see TypedArray.
Properties
-
Float32Array.BYTES_PER_ELEMENT -
Returns a number value of the element size.
4in the case of anFloat32Array. - Float32Array.length
- Length property whose value is 3.
-
Float32Array.name -
Returns the string value of the constructor name. In the case of the
Float32Arraytype: "Float32Array". -
Float32Array.prototype - Prototype for the TypedArray objects.
Methods
- Float32Array.from()
-
See
Array.from(). Not implemented, see bug 896608. - Float32Array.of()
-
See
Array.of(). Not implemented, see bug 896608.
Float32Array prototype
All Float32Array objects inherit from %TypedArray%.prototype.
Properties
-
Float32Array.prototype.constructor -
Returns the function that created an instance's prototype. This is the
Float32Arrayconstructor by default. -
Float32Array.prototype.bufferRead only -
Returns the
ArrayBufferreferenced by theFloat32ArrayFixed at construction time and thus read only. -
Float32Array.prototype.byteLengthRead only -
Returns the length (in bytes) of the
Float32Arrayfrom the start of itsArrayBuffer. Fixed at construction time and thus read only. -
Float32Array.prototype.byteOffsetRead only -
Returns the offset (in bytes) of the
Float32Arrayfrom the start of itsArrayBuffer. Fixed at construction time and thus read only. -
Float32Array.prototype.lengthRead only -
Returns the number of elements hold in the
Float32Array. Fixed at construction time and thus read only.
Methods
-
Float32Array.prototype.copyWithin() -
See
Array.prototype.copyWithin(). -
Float32Array.prototype.move()Unimplemented -
Former non-standard version of
Float32Array.prototype.copyWithin(). -
Float32Array.prototype.set() -
Stores multiple values in the
Float32Array, reading input values from a specified array. -
Float32Array.prototype.subarray() -
Returns a new
Float32Arrayfrom the given start and end element index.
Examples
// From a length var float32 = new Float32Array(2); float32[0] = 42; console.log(float32[0]); // 42 console.log(float32.length); // 2 console.log(float32.BYTES_PER_ELEMENT); // 4 // From an array var arr = new Float32Array([21,31]); console.log(arr[1]); // 31 // From another TypedArray var x = new Float32Array([21, 31]); var y = new Float32Array(x); console.log(y[0]); // 21 // From an ArrayBuffer var buffer = new ArrayBuffer(16); var z = Float32Array(buffer, 0, 4);
Specifications
| Specification | Status | Comment |
|---|---|---|
| Typed Array Specification | Obsolete | Superseded by ECMAScript 6. |
| ECMAScript 6 (ECMA-262) The definition of 'TypedArray constructors' in that specification. |
Draft | Initial definition in an ECMA standard. |
Browser compatibility
Help improve compatibility tables by filling out this 11 question survey.
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 7.0 | 4.0 (2) | 10 | 11.6 | 5.1 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | 4.0 | (Yes) | 4.0 (2) | 10 | 11.6 | 4.2 |
See also
Document Tags and Contributors
Tags:
Contributors to this page: Sheppy, fscholz, BennettJames, yyss, tszynalski, kscarfone, teoli, Nfroidure, amaneight, robinst, Reachmeatshivam
Last updated by:
fscholz,