Why can't I push objects into array from callback function in node.js?
<p>I'm trying to learn node.js by using "learnyounode". There is an excercise where one is supposed to take a folder-path and a file-extension type as input and then give all files of that type in that folder as output. I have constructed this program:</p>

<pre><code>var fs = require('fs');
var pathModule = require('path');
var path = process.argv[2];
var ext = '.'.concat(process.argv[3]);
filteredList = [];
fs.readdir(path,function doneReading(err, list){
    for(var i = 0; i &lt; list.length; i++){
        if(pathModule.extname(list[i]) == ext){
            filteredList.push(list[i]);
        }
    }
    })

for(var i = 0; i &lt; filteredList.length; i++){
    console.log(filteredList[i]);
}
</code></pre>

<p>and for some reason the </p>

<pre><code>filteredList.push(list[i]);
</code></pre>

<p>has no effect on the contents of the filteredList. Why is this? I have solved the excercise by moving the console.log to inside the readdir-function, but I have no idea why the psuh doesn't work.</p>