Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks for all the answers and the input. Very interesting were the results of the test written by galamalazs: <a href="http://jsperf.com/object-vs-array/2" rel="nofollow">http://jsperf.com/object-vs-array/2</a></p> <p>Taking all aspects together we'll get:</p> <ul> <li>Arrays should be indexed by number and not by string (arr[0] vs. arr['0'])</li> <li>Performance between the Object and the Array form differs mostly by implementation not by type.</li> <li>There is no winner, it changes from implementation to implementation</li> <li>Future implementations of the browsers known today might also change who's winning - in either way</li> <li>On Chromium the Arrays will use half the memory of the Object - but we are talking about 40 MB and 80 MB for one million instances - that is 40 to 80 bytes each.</li> <li>The memory consumption of other JavaScript implementations is not known - but it'll most probably also differ as much as the performance.</li> </ul> <p>So in the end both options are sensible and only the code readability will make the decision!</p> <p>If it's mostly for storing data with trivial work (like in my current project) the Object way is the way to go. An <code>mouse.x</code> and <code>mouse.y</code> trivially shows the developer intend.</p> <p>In mostly mathematically oriented applications with vector maths like coordinate transformations (especially going to 3D) the best way would be the Array case as things like matrix multiplications would look more native to the developer and show his intent.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload