> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 将 ArrayBuffer 转换为数字数组

要获取 `ArrayBuffer` 的内容作为数字数组，可在该缓冲区上创建一个 [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)，然后使用 [`Array.from()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from) 将其转换为数组。

```ts theme={null}
const buf = new ArrayBuffer(64);
const arr = new Uint8Array(buf);
arr.length; // 64
arr[0]; // 0（初始化为全零）
```

***

`Uint8Array` 类支持数组索引和迭代。要将实例转换为常规 `Array`，请使用 `Array.from()`。这可能比直接使用 `Uint8Array` 慢一些。

```ts theme={null}
const buf = new ArrayBuffer(64);
const uintArr = new Uint8Array(buf);
const regularArr = Array.from(uintArr);
// number[]
```

***

参见 [二进制数据](/runtime/binary-data#conversion)。
