> ## 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 转换为 Uint8Array

`Uint8Array` 是一种 *类型化数组*，意味着它是一种查看底层 `ArrayBuffer` 中数据的机制。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const buffer = new ArrayBuffer(64);
const arr = new Uint8Array(buffer);
```

***

其他类型化数组的实例也可以类似创建。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const buffer = new ArrayBuffer(64);

const arr1 = new Uint8Array(buffer);
const arr2 = new Uint16Array(buffer);
const arr3 = new Uint32Array(buffer);
const arr4 = new Float32Array(buffer);
const arr5 = new Float64Array(buffer);
const arr6 = new BigInt64Array(buffer);
const arr7 = new BigUint64Array(buffer);
```

***

若想创建一个仅查看底层缓冲区部分内容的类型化数组，可以向构造函数传入偏移量和长度。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const buffer = new ArrayBuffer(64);
const arr = new Uint8Array(buffer, 0, 16); // 查看前 16 个字节
```

***

更多实用工具请参见[文档 > API > 工具](/runtime/utils)。
