title: How are JavaScript arrays implemented?
body: <p>Namely, how does the following code:</p>
  <pre><code>var sup = new Array(5);
  sup[0] = 'z3ero';
  sup[1] = 'o3ne';
  sup[4] = 'f3our';
  document.write(sup.length + &quot;&lt;br /&gt;&quot;);
  </code></pre>
  <p>output '5' for the length, when all you've done is set various elements?</p>
  <p>My 'problem' with this code is that I don't understand how <code>length</code> changes without calling a <code>getLength()</code> or a <code>setLength()</code> method. When I do any of the following:</p>
  <pre><code>a.length
  a['length']
  a.length = 4
  a['length'] = 5
  </code></pre>
  <p>on a non-array object, it behaves like a dict / associative array. When I do this on the array object, it has special meaning. What mechanism in JavaScript allows this to happen? Does JavaScript have some type of property system which translates</p>
  <pre><code>a.length
  a['length']
  </code></pre>
  <p>into &quot;get&quot; methods and</p>
  <pre><code>a.length = 4
  a['length'] = 5
  </code></pre>
  <p>into &quot;set&quot; methods?</p>