考虑这段代码:
var b = new ArrayBuffer(2);
b[0] = 1;
b[1] = 23234322442;
单元格 1 中的数字明显大于 1 个字节,但 ArrayBuffer 存储它没有问题,当我打印 b
到控制台时,我可以看到数字就在那里。有何解释?
谢谢。
最佳答案
The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. 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. more
所以,我认为,当您调用 b[1]
时,您不会设置缓冲区的第二个元素。您只需设置对象的 b.1
属性,它可以是任何内容(数字、字符串、对象、数组)。
关于node.js - Node js - 在 ArrayBuffer 中存储大量数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38655707/