It outputs this:
We want output like this:
What's the solution to this basic problem ?
The problem is that the variable i, within each of your anonymous functions, is bound to the same variable outside of the function.
You can try this:
You can use
The function to be created from outside the loop and then binding the results within the loop.
Using an Immediately-Invoked Function Expression, the simplest way to readable and enclose an index variable:
Read Alsonode.js - While Loop