Skip to content

Instantly share code, notes, and snippets.

@d-simon
Created March 7, 2014 00:49
Show Gist options
  • Save d-simon/9402916 to your computer and use it in GitHub Desktop.
Save d-simon/9402916 to your computer and use it in GitHub Desktop.
For-Loop / Pass iterator into async callback
for (var i = 0; i < array.length; i++) (function (i, arrayElement) {
// this will create a new variables i and arrayElement for each loop iteration
// so we can use it in an async callback
doSomeAsync(function callback () {
console.log(i, arrayElement);
});
}) (i, array[i]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment