Why the array is undefined? : <p>In following code snippet why I see undefined logged?However if I separate  call to range method and store in some local variable then perform <code>foreach</code> ,it works fine.</p>

<pre><code>    var range = function (max) {
        var result = [];
        var index;
        for (index = 0; index &lt;= max; index = index + 1) {
            result.push(index);
        }
        return result;
    };


   var arr=  range(100).forEach(function (number, index,array) {
        if (number % 3 == 0) {
            array[index] = "c";
        }
    });

    console.log(arr);
</code></pre>
