Javascript Array lookup efficiency: associative vs. stored associative?

后端 未结 4 459
逝去的感伤
逝去的感伤 2021-02-04 19:52

I\'ve been reading, and they\'re saying that associative arrays won\'t give you the same efficiency as arrays. An associative array can look things up in O(N) time, where an ar

4条回答
  •  天命终不由人
    2021-02-04 20:35

    Answer: test it out yourself.

    Update: After some back-and-forth with Felix, it appears that array access is usually faster than both associative arrays and objects. This is not always the case, notably in Chrome. In Chrome 11 on Ubuntu 11, arrays are faster. In Chrome 11 on Mac OS 10.6 there is no notable difference between them.

    These tests did not measure manipulation, only reading.

提交回复
热议问题