The callback function is executed asynchonously, after the loop over the items has ended. And at the end of the loop, i
is equal to 2, since there are 2 items in your items
array.
See Javascript infamous Loop issue? for another example of the same behavior, and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Closures#Creating_closures_in_loops.3A_A_common_mistake for an more in-depth explanation.