Last updated on

Sparse Arrays

中文 Sparse Arrays 叫作稀疏数组

控制台打印会展示

(8) [empty × 8]

一些老的 API 执行会跳过这些 empty 的数组,新的会把这些 empty 作为 undefined 来执行

以下内容摘自 MDN

Array methods and empty slots

Empty slots in sparse arrays behave inconsistently between array methods. Generally, the older methods will skip empty slots, while newer ones treat them as undefined.

Among methods that iterate through multiple elements, the following do an in check before accessing the index and do not conflate empty slots with undefined:

For exactly how they treat empty slots, see the page for each method.

These methods treat empty slots as if they are undefined: