Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

171 - 为什么说在js中数组不是真正意义上的数组? #171

Open
bettersong opened this issue Mar 22, 2022 · 0 comments
Open

Comments

@bettersong
Copy link
Owner

bettersong commented Mar 22, 2022

在数据结构中数组是由相同类型的元素的集合所组成的数据结构,分配在一段连续的内存中

但是在js中数组的定义可以是这样

let arr = ["nanjiu", 18 ,{gender: 'boy'}]

可以看到它并不是同一数据类型

而不同的数据类型在内存中分配的空间也是不同的

而由于js是弱类型语言,空间无法固定,所以也不是连续的内存

所以其他的语言定义数组是固定长度因为数据类型相同是连续分配的内存,因此JavaScript中数组的长度并不固定,其实再js中的数组是map类型,包含key和value

js中有快数组和慢数组两种模式

快数组是牺牲内存来提升性能,慢数组相反

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant