Float32Array
类型数组代表的是平台字节顺序为32位的浮点数型数组(对应于 C 浮点数据类型) 。 如果需要控制字节顺序, 使用 DataView
替代。其内容初始化为0
。一旦建立起来,你可以使用这个对象的方法对其元素进行操作,或者使用标准数组索引语法 (使用方括号)。
new Float32Array(length);
new Float32Array(typedArray);
new Float32Array(object);
new Float32Array(buffer [, byteOffset [, length]]);
更多的语法信息和参数,参见 TypedArray。
Float32Array.BYTES_PER_ELEMENT
在
Float32Array的情况下返回4。
Float32Array.prototype.length
。Float32Array.name
Float32Array
类型的情况下为:"Float32Array"。Float32Array.prototype
Float32Array.from()
Array.from()
。Float32Array.of()
Array.of()
。Float32Array
属性所有的Float32Array对象都
继承自 %TypedArray%.prototype
。
Float32Array.prototype.constructor
Float32Array
默认的构造函数。Float32Array.prototype.buffer
只读 Float32Array引用的
ArrayBuffer
。构造时已固定,所以是只读的。Float32Array.prototype.byteLength
只读 Float32Array的
ArrayBuffer
开头开始的
长度 (以字节为单位) 。构造时已固定,所以是只读的。Float32Array.prototype.byteOffset
只读 Float32Array的
ArrayBuffer
开头开始的偏移量
(以字节为单位) 。构造时已固定,所以是只读的。Float32Array.prototype.length
只读 Float32Array中的元素个数
。构造时已固定,所以是只读的。Float32Array.prototype.copyWithin()
Array.prototype.copyWithin()
。Float32Array.prototype.entries()
返回一个包含数组中每个元素键值对的数组遍历器对象
。参见Array.prototype.entries()
。Float32Array.prototype.every()
Array.prototype.every()
。Float32Array.prototype.fill()
Array.prototype.fill()
。Float32Array.prototype.filter()
Array.prototype.filter()
。Float32Array.prototype.find()
Array.prototype.find()
。Float32Array.prototype.findIndex()
Array.prototype.findIndex()
。Float32Array.prototype.forEach()
Array.prototype.forEach()
。Float32Array.prototype.includes()
返回true
或 false
。参见Array.prototype.includes()
。Float32Array.prototype.indexOf()
Array.prototype.indexOf()
。Float32Array.prototype.join()
Array.prototype.join()
。Float32Array.prototype.keys()
返回一个包含数组中所有索引的数组遍历器
。 参见Array.prototype.keys()
。Float32Array.prototype.lastIndexOf()
Array.prototype.lastIndexOf()
。Float32Array.prototype.map()
Array.prototype.map()
。Float32Array.prototype.move()
未实现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
。Float32Array.prototype.values()
Array.prototype.values()
。Float32Array.prototype.toLocaleString()
Array.prototype.toLocaleString()
。Float32Array.prototype.toString()
Array.prototype.toString()
。Float32Array.prototype[@@iterator]()
// 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);
规范 | 状态 | 注释 |
---|---|---|
Typed Array Specification | Obsolete | 被ECMAScript 6取代 |
ECMAScript 2015 (6th Edition, ECMA-262) TypedArray constructors |
Standard | 在ECMA中初始定义,另外规定需要使用new。 |
ECMAScript Latest Draft (ECMA-262) TypedArray constructors |
Draft |
特性 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
基础支持 | 7.0 | 4.0 (2) | 10 | 11.6 | 5.1 |
需要new |
? | 44 (44) | ? | ? | ? |
特性 | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
基础支持 | 4.0 | (Yes) | 4.0 (2) | 10 | 11.6 | 4.2 |
需要new |
? | ? | 44.0 (44) | ? | ? | ? |
从ECMAScript 2015 (ES6)开始, Float32Array
构造函数需要用一个new
操作符来构造。现在直接把Float32Array构造函数当函数调用而不使用new,会抛出一个
TypeError
。
var dv = Float32Array([1, 2, 3]);
// TypeError: calling a builtin Float32Array constructor
// 不允许不使用new
var dv = new Float32Array([1, 2, 3]);