Content-Length: 461475 | pFad | https://bun.com/guides/binary/arraybuffer-to-array

X Convert an ArrayBuffer to an array of numbers - Bun
Skip to main content
To retrieve the contents of an ArrayBuffer as an array of numbers, create a Uint8Array over of the buffer. and use the Array.from() method to convert it to an array.
const buf = new ArrayBuffer(64);
const arr = new Uint8Array(buf);
arr.length; // 64
arr[0]; // 0 (instantiated with all zeros)

The Uint8Array class supports array indexing and iteration. However if you wish to convert the instance to a regular Array, use Array.from(). (This will likely be slower than using the Uint8Array directly.)
const buf = new ArrayBuffer(64);
const uintArr = new Uint8Array(buf);
const regularArr = Array.from(uintArr);
// number[]

See Docs > API > Binary Data for complete documentation on manipulating binary data with Bun.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://bun.com/guides/binary/arraybuffer-to-array

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy