JSFiddle - React, Tailwind, and code Playground
by Vasiliy
JavaScript
const array = [10, 20, 30, 40, 50];
for (var i = 0; i < array.length; i++) {
setTimeout(() => {
return () => {
console.log(`Current index is ${index}, element value is ${array[index]}`);
}
}, 3000);
}
// Current index is 0, element value is 10
// Current index is 1, element value is 20
// Current index is 2, element value is 30
// Current index is 3, element value is 40
// Current index is 4, element value is 50