ArrayBuffer 转换为清零的 Uint8Array

ArrayBuffer converts to zero'd out Uint8Array

我正在尝试将数组缓冲区转换为 Uint8Array,但结果始终为零。

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]

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.