Need help understanding why javascript object property is undefined
<p>I need help understanding why the following piece of code returns an undefined object property: </p>

<pre><code>var count = 0;
var intervals = {
    collection : []                      
}

intervals.collection[0] = function () {
    this.timer = setInterval(function(){
       count++;
       $("p").html(count);            
    }, 1000);
}();

if(typeof intervals.collection[0] === "undefined") {
    $("span").html("undefined");        
}​
</code></pre>

<p>Working Example: <a href="http://jsfiddle.net/tvaQk/8/" rel="nofollow">http://jsfiddle.net/tvaQk/8/</a></p>

<p>Basically, I'd like to be able to keep a collection of setIntervals that I can reference later so I can loop through and clear. I was thinking I'd be able to loop through the intervals.collection array and do something like:</p>

<p><code>clearInterval(intervals.collection[0].timer)</code></p>

<p>but cannot since <code>intervals.collection[0]</code> is undefined</p>
