title: Creating a file for each response from an API call with a FOR loop
body: <p>I am trying to create a file for each response from an API call with a for loop, but when i try to use interop it give the error: </p>
  
  <blockquote>
    <p>i is not defined even though it is define when the loop uses it to make API calls</p>
  </blockquote>
  
  <pre><code>function sysWrite(data){
    fs.appendFile(`${testArray[i}[1]}.json`, data, function(err){
      if(err) throw err;
    })
  }
  
  forLoop().then(function (resSet){
    for(i = 0; i &lt; resSet.length; i++){
      (function(i){
        setTimeout(function(){
          axios.get(`https://api.census.gov/data/2016/acs/acs5?get=NAME,${resSet[i]}&amp;for=state:*&amp;key=${censusAPI}`)
          .then(function (response) {
            //problem place
            let replacedKey = Object.assign({}, response.data);
            let jsonData =  JSON.stringify(replacedKey).replace(testArray[i][0], testArray[i][1]);
            sysWrite(jsonData)
          })
          .catch(function (error) {
            console.log(error);
          });
        }, 100*i)
      })(i);
    }
  })
  </code></pre>