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

`Uint8Array` 是一种\_类型化数组\_，是对底层 `ArrayBuffer` 中数据的视图。

```ts theme={null}
const buffer = new ArrayBuffer(64);
const arr = new Uint8Array(buffer);
```

***

用同样的方式创建其他类型化数组的实例。

```ts theme={null}
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={null}
const buffer = new ArrayBuffer(64);
const arr = new Uint8Array(buffer, 0, 16); // 查看前 16 个字节
```

***

参见 [工具](/runtime/utils)。
