JSFiddle - React, Tailwind, and code Playground
JavaScript
//anonystick.com
var elements = ["element1", "element2", "element3"];
//This is how it is supposed to be implemented usingforEach:
elements.forEach(function(element) {
// The asynchronous action simulator
setTimeout(function() {
console.log(element);
}, 100);
});
//Without knowing about forEach() I would start with a classic for(;;) loop:
for (var i = 0; i < elements.length; i++) {
setTimeout(function() {
console.log(elements[i]);
}, 100);
}
//using let with for
for (let i = 0; i < elements.length; i++) {
setTimeout(function() {
console.log(elements[i]);
}, 100);
}