Javascript array with default values (equivalent of Python's defaultdict)?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/11503666/set-undefined-javascript-property-before-read">Set undefined javascript property before read</a>  </p>
</blockquote>



<p>Is there an equivalent of <a href="http://docs.python.org/library/collections.html#collections.defaultdict" rel="nofollow">Python's defaultdict</a> in Javascript? This would be a Javascript array where the value returned for a missing key is definable. Something like:</p>

<pre><code>var a = defaultArray("0");
console.log(a['dog']);
// would print 0
</code></pre>

<p>If not, how would you implement it?</p>
