如何从ArrayBuffer获取数组? [英] How to get an array from ArrayBuffer?

查看:113
本文介绍了如何从ArrayBuffer获取数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ArrayBuffer,看起来像:

I have an ArrayBuffer which looks like:

此缓冲区放置在名为 myBuffer 的变量下,我感兴趣的是从此对象获取 Uint8Array .

This buffer is placed under variable named myBuffer and what I'm interested in, is to get the Uint8Array from this object.

我试图循环为:

myBuffer.forEach(function(element) {
    console.log(element);
});

并以以下方式直接访问数组:

and to directly access to the Array as:

console.log(myBuffer['[[Uint8Array]]']);
console.log(myBuffer['Uint8Array']);

但是似乎这都不是正确的方法

but seems none of this is the correct approach

推荐答案

您看到的那些伪属性是开发者控制台为了您的利益而放置的.作为属性或符号(AFAIK),它们根本就不存在,即使它们是非标准的.

Those pseudo-properties you are seeing are something the developer console is putting there for your benefit. They aren't really there at all, as a property or a symbol (AFAIK), and even if they were it would be non-standard.

您可以像这样通过标准方式轻松获得缓冲区的 Uint8Array 视图:

You can easily get a Uint8Array view of your buffer the standard way like this though:

new Uint8Array(myBuffer)

这篇关于如何从ArrayBuffer获取数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆