[英]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.我正在尝试将数组缓冲区转换为 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]
Quoting the docs at ArrayBuffer引用ArrayBuffer 上的文档
You cannot directly manipulate the contents of an
ArrayBuffer
;您不能直接操作
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.相反,您创建一个类型化数组对象或一个以特定格式表示缓冲区的 DataView 对象,并使用它来读取和写入缓冲区的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.