title: fs.write() in a for loop
body: <p>i am writing a code in which i have to create files equal to number of elements in a array and write respective array element in files.
  for example array = [one,two,three], then i want to have file one with content one and so on.</p>
  
  <pre><code>var inputLength = inputs.length;
  
  inputs.forEach(function(elem) {
      i = inputs.indexOf(elem);
      console.log(i);
      fs.writeFile(Execute.path + Execute.folder + "/inputFile" + i, elem, function(err) {
          if (err) {
              console.log(err);
          } else {
              console.log("Input" + i + " file was saved!");
          }
  
      });
  
  
      console.log(i);
  
  
  });
  </code></pre>
  
  <p>output of first <code>console.log(i)</code> is fine i.e. 0,1,2,3 so on but output of second <code>console.log(i)</code> is always the index of last element.</p>
  
  <p>whats the problem in my code and how to achieve my goal</p>