Executing functions in a loop in javascript
<p>I'm clearly missing something in Java Script. I'd like to execute the same function with different parameters sequentially in a for loop (like in the commented part of code).
I'm instead using callback, but I guess it's not the nicest way, and not flexible, for example if I had more paths to be looped over. What the cleanest approach in sewuentially executing functions?</p>

<pre><code>var data = '';
var filepath = ['path1', 'path2'];
somefunction(filepath, callback) {
    //dosth ();
    callback();
}

//filepath = ['path1', 'path2'];
//for ( var i = 0; i &lt; filepath.length; i = i + 1 ) {
//   somefunction( filepath[i] );
//}
somefunction( filepath[0] , function() {
    console.log("Finished processing file 1");
    countFromFile( filepath[1], function() {
        console.log("Finished processing file 2");
        saveToFile( data );
    });
});     
</code></pre>
