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

JS算法相关: 数组中有10万条数据, 取第1条和第10万条的时间相差多少 #91

Open
leslie1943 opened this issue Dec 14, 2020 · 0 comments

Comments

@leslie1943
Copy link
Owner

leslie1943 commented Dec 14, 2020

结论

消耗时间几乎一致(差异可以忽略不计)

原因

  • JavaScript中没有真正的数组, 所有的数组其实都是对象, 其索引看起来是数字,其实会被转换成字符串, 作为属性名(对象的key)来使用, 所以无论是取第1个还是取第10万个, 都是使用key精确查找哈比表的过程, 消耗时间大致相同.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant