title: Pass extra parameter to jQuery getJSON() success callback function
body: <p>I've never had to use callback functions before, so I may have made a completely stupid mistake. I think I somewhat understand the problem here, but not how to solve it.</p>
  
  <p>My code (a bit simplified) is:</p>
  
  <pre><code>for (var i = 0; i &lt; some_array.length; i++) {
      var title = some_array[i];
      $.getJSON('some.url/' + title, function(data) {
          do_something_with_data(data, i);
      }
  </code></pre>
  
  <p>Now as far as I understand, this anonymous function will only be called if getJSON() has received the data. But by this point, <code>i</code> does not have the value I would require. Or, as far as my observation goes, it has the last value it would have after the loop is done (shouldn't it be out of bounds?).</p>
  
  <p>As a result, if the array had a size of 6, <code>do_something_with_data()</code> would be called five times with the value 5.</p>
  
  <p>Now I thought, just pass <code>i</code> to the anonymous function</p>
  
  <pre><code>function(data, i) { }
  </code></pre>
  
  <p>but this does not seem to be possible. <strong>i</strong> is undefined now.</p>