Javascript and Jquery loop array in Javascript constructor
<p>Can anyone explain the following to me please.</p>

<p>Case 1: <br /></p>

<pre><code>function MyObj () {

    this.myArray = new Array();

    for(var i = 0; i&lt;5; i++){
        this.myArray.push(i);
        console.log("add to array:" + i);
    }
}
</code></pre>

<p>which works as I expected. this.myArray has 0,1,2,3,4.</p>

<p>Case 2:</p>

<pre><code>function MyObj () {

    this.myArray = new Array();

    $.each([0,1,2,3,4],function(i,v){   
        this.myArray.push(i);
        console.log("add to array:" + v);
    });
}
</code></pre>

<p>I got complains from Firebug "this.myArray is undefined."</p>

<p>Thanks.</p>
