Dellowar
Dellowar

Reputation: 3352

ArrayBuffer converts to zero'd out Uint8Array

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

Answers (1)

Gabriele Petrioli
Gabriele Petrioli

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

Related Questions