# 数组

> 数组是一种线性表数据结构。它用一组连续的内存空间，来存储一组具有相同类型的数据。 ——数据结构与算法之美

![](/files/-Lxe-cFdK5yIbgG8DQCC)

js 原本没有真正的数组，因为 js 的数组可以存放不同类型的数据，不同数据类型存储所需要的空间大小不同，这就导致用来存放数组的内存地址不可能是连续的。所以 **js 的数组是按照类似哈希映射的方法存储的**，这种方式的数组读写操作相对低效。

v8 引擎对数组做了优化，如果一个数组中所有的类型都是一样的，那么就在内存中开辟一个连续的空间来储存数组。但是如果数组中又添加了一个不同的类型，那么 v8 引擎就会按之前的老办法将数组重建，这时反而会更低效。

ES6 的新增了 `ArrayBuffer` ，它可以创建内存空间连续的数组。显而易见，对通过 `ArrayBuffer` 创建的数组进行遍历操作，速度更快。<br>

![](/files/-Lxe-hzIKYlOaStOHDax)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mm.ricky.moe/algorithm/algorithm-and-data-structure/shu-ju-jie-gou/shu-zu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
