Skip to main content

Convert an ArrayBuffer to an array of numbers

还没翻译译自英文(bun.com)本页 4 段都还没译

To retrieve the contents of an ArrayBuffer as an array of numbers, create a Uint8Array over the buffer, then use Array.from() 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. To convert the instance to a regular Array, use Array.from(). This is likely slower than using the Uint8Array directly.

const buf = new ArrayBuffer(64);
const uintArr = new Uint8Array(buf);
const regularArr = Array.from(uintArr);
// number[]

See Binary Data.

译文 © 2026 fanyi.dev · 原文 © 2026 the Bun project (LICENSE.md names no copyright holder) (MIT)