Leslie
0
Q:

javascript pass iterator to callback

makeHTTPRequest('GET', 'http://youramazingapi/money_makers.php').then(function(data){
    this.shakeThose.push(data);
}.bind(this));
0
//use let keywork and i will increment correctly inside loops
for (let i = 0; i < a.length; i++) {
   makeHttpReqest("http://www.codegrepper.com", function(response) {
       // i will increment correctly here; 
 
  });
}

//Alternatively, if you can't use let, this syntax will work too
for (var i = 0; i < a.length; i++) (function(i)
{
   makeHttpReqest("http://www.codegrepper.com", function(response) {
       // i will increment correctly here; 
 
  });
}) (i);
0
for (var i = 0; i < a.length; i++) (function(i)
{          
	//some function here
  
}) (i);
0

New to Communities?

Join the community