How can I convert a Uint8ClampedArray
(like one used for storing HTML5 canvas image data) to a regular array, in which values won't be constrained to 0
-255
?
You can convert a typed array to a regular array by using Array.prototype.slice
var typedArray = new Uint8ClampedArray([1, 2, 3, 4]);
var normalArray = Array.prototype.slice.call(typedArray);
Also if using ES6 you may be able to use Array.from
instead:
var normalArray = Array.from(typedArray);
See MDN - JavaScript typed arrays
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With