iterator method js code example

Example 1: java iterator example

Iterator iterator = list.iterator(); 
        System.out.println("List elements : "); 
        while (iterator.hasNext()) 
            System.out.print(iterator.next() + " ");

Example 2: what is an iterator in javascript

The iterator is an object that returns values via its method next()

Example 3: javascript iterator callback

//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);