I have a JavaScript Float32Array, and I would like to convert it into a regular JavaScript Array. How can I do this?
You can use it as any array, which means you can do this :
var arr = [];
for (var i=0; i<myFloat32array.length; i++) arr[i] = myFloat32array[i];
But it's usually more efficient to use it as a Float32Array instead of converting it.
If you don't want to mix different types of values, don't convert it.
Use Array.prototype.slice to convert float32Array
to Array. jsfiddle
var floatarr = new Float32Array(12);
var array = Array.prototype.slice.call(floatarr);
If you don't need to support old browsers (including IE, unfortunately), you can use Array.from, which was added to ES6:
var array = Array.from(floatarr);
This now works in the new releases of every browser (except IE), and it works on all major mobile browsers too.