title: Working with closures inside loops
body: <p>Okay so I've read <a href="https://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example/19323214#19323214">this closure question</a> and tried to fit the idea behind my script. This is what I have so far but the console is telling me that nameOfLoan[j] does not exist and I can't figure out why.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$('body').on('keyup', '.qForms', function() {
  var nameOfLoan = [];
  
   var loanOfName = function(t) {
     $('body').on('keyup', '.loanNameV'+t, function() {
       console.log('hi');
      var loanN = $('.loanNameV'+t).val();
      $('.nameLoan'+t).text(loanN);
     });
    };
  
   for (var t=1; t &lt; z; t++) {
    nameOfLoan[t] = loanOfName(t);
   }
  
   for (var j=1; j &lt; z; j++) {
    nameOfLoan[j]();
   }
  });</code></pre>
  </div>
  </div>
  </p>