Comments (3)
- 对于 JS 而言,数组变量其实就是一个指针,而数组的索引值表示偏移量的个数;
- 好像设计数组的时候,每个值的类型都是一样的,所以每一个存缓存的内存也是一样的,一个值所占的内存大小就是一个偏移量的大小;
- 所以对于数组的第一个值,就是指针所在的位置,偏移量为0;对于第二个值,就是偏移了第一个值的位置,所以是 start + 1 * 偏移量;
- 这样当我们用索引来求数组索引值为 N 的值的时候,给的是 arr[n] , 计算机到 start+n*K 就能找到所在位置了;如果以 1 开始,那么每次查找就要多处理一次 n-1 的操作 start+(n-1)*K
- 以上是一个小前端看了之前的书了解的,谢谢
from fe-interview.
- 索引的含义是偏移量(offset),偏移量从 0 开始,因此索引也从 0 开始。
- 数组需要支持随机访问,一种实现方式就是通过 基值+偏移量*每项的字节数 访问任意索引位置。如果索引从 1 开始,那么偏移量就等于索引-1,这样会多一次减法运算。
from fe-interview.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from fe-interview.
Related Issues (20)
- 【每日一题】- 2020-07-28 - Promise.all VS Promise. allSettled Promise.any VS Promise.race HOT 4
- 【每日一题】- 2020-08-03 - 多线程打印 HOT 5
- 【每日一题】- 2020-08-04 - 浏览器是如何解析 CSS rule 的? HOT 3
- 【每日一题】- 2020-08-05 - 运营商劫持 HOT 2
- 【每日一题】- 2020-08-06 - 讨厌的 Y HOT 3
- 【每日一题】- 2020-08-07 - 寻找祖先 HOT 5
- 【每日一题】- 2020-08-10 - JS 编程题 HOT 4
- 【节流防抖的概念弄混了】
- 【每日一题】- 2020-08-21 HOT 3
- 【每日一题】- 2020-08-25 - 编程范式 HOT 1
- 【每日一题】- 2020-09-02 - type A<T> = (x:T) => T; type B = <T>(x:T) => T; 的区别 HOT 3
- 【每日一题】- 2020-09-04 - 多个进程如何监听同一个端口 HOT 2
- 【每日一题】- 2020-09-15 - 响应头 content-type 的奇幻之旅 HOT 2
- 【每日一题】- 2020-10-09 - 以下 shell 的作用是什么? HOT 3
- 【每日一题】- 2020-10-16 - 分割数组 HOT 1
- 【每日一题】- 2020-10-21 - 字典分割 HOT 2
- 【每日一题】- 2020-04-19 - !!~A.indexOf(edge._label) 是什么意思? HOT 3
- 【开源自荐】推荐一个每日更新的前端面试题库
- 【开源自荐】SolidUI 一句话生成任何图形
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fe-interview.