> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/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={"theme":{"light":"github-light","dark":"dracula"}}
const buf = new ArrayBuffer(64);
const arr = new Uint8Array(buf);
arr.length; // 64
arr[0]; // 0 (初始化为全零)
```

***

`Uint8Array` 类支持数组索引和迭代。但是如果你希望将该实例转换为普通的 `Array`，请使用 `Array.from()`。（这通常比直接使用 `Uint8Array` 会更慢。）

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const buf = new ArrayBuffer(64);
const uintArr = new Uint8Array(buf);
const regularArr = Array.from(uintArr);
// number[]
```

***

参见 [文档 > API > 二进制数据](/runtime/binary-data#conversion) 获取关于使用 Bun 操作二进制数据的完整文档。
