First of all, the output will be four times, not five times (as indicated in your comment). I pasted your code in Babel REPL, and this is what I got,
"use strict";
var arr = [1, 2, 3, 4];
var _loop = function _loop(i) {
setTimeout(function () {
console.log(arr[i]);
}, 1000);
};
for (var i = 0; i < arr.length; i++) {
_loop(i);
}
Do you see how now you can work inside ?:-)
source
share