Reputation: 3352
I'm trying to convert an array buffer to a Uint8Array and it alwasy comes out as zeros.
buff = new ArrayBuffer(4)
buff[0] = 10
buff[1] = 10
buff[2] = 10
buff[3] = 10
console.log(new Uint8Array(buff))
-> Uint8Array(4) [0, 0, 0, 0]
Upvotes: 2
Views: 611
Reputation: 195992
Quoting the docs at ArrayBuffer
You cannot directly manipulate the contents of an
ArrayBuffer
; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.
Upvotes: 2