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).
new Float32Array(); // new in ES2017 new Float32Array(length); new Float32Array(typedArray); new Float32Array(object); new Float32Array(buffer [, byteOffset [, length]]);
For more information about the constructor syntax and the parameters, see TypedArray.
Float32Array.BYTES_PER_ELEMENT
4
in the case of an Float32Array
.Float32Array.prototype.length
.Float32Array.name
Float32Array
type: "Float32Array".Float32Array.prototype
Float32Array.from()
Float32Array
from an array-like or iterable object. See also Array.from()
.Float32Array.of()
Float32Array
with a variable number of arguments. See also Array.of()
.Float32Array
prototypeAll Float32Array
objects inherit from %TypedArray%.prototype
.
Float32Array.prototype.constructor
Float32Array
constructor by default.Float32Array.prototype.buffer
Read only
ArrayBuffer
referenced by the Float32Array
Fixed at construction time and thus read only.Float32Array.prototype.byteLength
Read only
Float32Array
from the start of its ArrayBuffer
. Fixed at construction time and thus read only.
Float32Array.prototype.byteOffset
Read only
Float32Array
from the start of its ArrayBuffer
. Fixed at construction time and thus read only.
Float32Array.prototype.length
Read only
Float32Array
. Fixed at construction time and thus read only.
Float32Array.prototype.copyWithin()
Array.prototype.copyWithin()
.Float32Array.prototype.entries()
Array Iterator
object that contains the key/value pairs for each index in the array. See also Array.prototype.entries()
.Float32Array.prototype.every()
Array.prototype.every()
.Float32Array.prototype.fill()
Array.prototype.fill()
.Float32Array.prototype.filter()
Array.prototype.filter()
.Float32Array.prototype.find()
undefined
if not found. See also Array.prototype.find()
.Float32Array.prototype.findIndex()
Array.prototype.findIndex()
.Float32Array.prototype.forEach()
Array.prototype.forEach()
.Float32Array.prototype.includes()
true
or false
as appropriate. See also Array.prototype.includes()
.Float32Array.prototype.indexOf()
Array.prototype.indexOf()
.Float32Array.prototype.join()
Array.prototype.join()
.Float32Array.prototype.keys()
Array Iterator
that contains the keys for each index in the array. See also Array.prototype.keys()
.Float32Array.prototype.lastIndexOf()
Array.prototype.lastIndexOf()
.Float32Array.prototype.map()
Array.prototype.map()
.Float32Array.prototype.move()
Unimplemented
Float32Array.prototype.copyWithin()
.Float32Array.prototype.reduce()
Array.prototype.reduce()
.Float32Array.prototype.reduceRight()
Array.prototype.reduceRight()
.Float32Array.prototype.reverse()
Array.prototype.reverse()
.Float32Array.prototype.set()
Float32Array.prototype.slice()
Array.prototype.slice()
.Float32Array.prototype.some()
Array.prototype.some()
.Float32Array.prototype.sort()
Array.prototype.sort()
.Float32Array.prototype.subarray()
Float32Array
from the given start and end element index.Float32Array.prototype.values()
Array Iterator
object that contains the values for each index in the array. See also Array.prototype.values()
.Float32Array.prototype.toLocaleString()
Array.prototype.toLocaleString()
.Float32Array.prototype.toString()
Array.prototype.toString()
.Float32Array.prototype[@@iterator]()
Array Iterator
object that contains the values for each index in the array.Different ways to create a Float32Array
:
// 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 = new Float32Array(buffer, 0, 4); // From an iterable var iterable = function*(){ yield* [1,2,3]; }(); var float32 = new Float32Array(iterable); // Float32Array[1, 2, 3]
Specification | Status | Comment |
---|---|---|
Typed Array Specification | Obsolete | Superseded by ECMAScript 2015. |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'TypedArray constructors' in that specification. | Standard | Initial definition in an ECMA standard. Specified that new is required. |
ECMAScript Latest Draft (ECMA-262) The definition of 'TypedArray constructors' in that specification. | Draft | ECMAScript 2017 changed the Float32Array constructor to use the ToIndex operation and allows constructors with no arguments. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 7 | Yes | 4 | 10 | 11.6 | 5.1 |
Float32Array() without new throws |
Yes | Yes | 44 | No | Yes | ? |
Iterable in constructor | ? | ? | 52 | ? | ? | ? |
Constructor without arguments | ? | ? | 55 | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 4 | Yes | Yes | 4 | 11.6 | 4.2 | Yes |
Float32Array() without new throws |
? | ? | ? | 44 | ? | ? | ? |
Iterable in constructor | ? | ? | ? | 52 | ? | ? | ? |
Constructor without arguments | ? | ? | ? | 55 | ? | ? | ? |
Server | |
---|---|
Node.js | |
Basic support | 0.10 |
Float32Array() without new throws |
0.12 |
Iterable in constructor | 4.0.0 |
Constructor without arguments | ? |
Starting with ECMAScript 2015, Float32Array
constructors require to be constructed with a new
operator. Calling a Float32Array
constructor as a function without new
, will throw a TypeError
from now on.
var dv = Float32Array([1, 2, 3]); // TypeError: calling a builtin Float32Array constructor // without new is forbidden
var dv = new Float32Array([1, 2, 3]);
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array