How to get an array from ArrayBuffer?

后端 未结 2 869
独厮守ぢ
独厮守ぢ 2021-01-18 02:46

I have an ArrayBuffer which looks like:

This buffer is placed under variable named myBuffer and what I\'m interested in, is to get the Uint8Arra

相关标签:
2条回答
  • 2021-01-18 02:58

    You will first need to convert the array buffer into a typed array, then from there you can use the spread operator to create an array

    const typedArray = new Uint8Array(myBuffer);
    const array = [...typedArray];
    
    0 讨论(0)
  • 2021-01-18 03:18

    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.

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

    new Uint8Array(myBuffer)
    
    0 讨论(0)
提交回复
热议问题