I'm building some Node.js app and have a function like this:
function ex() {
allowUA = false;
for (var i = 0; i < arr.length; i++) {
(function(index) {
setTimeout(() => {
console.log(index);
}, i * 3000);
})(i);
}
if (i == arr.length - 1) {
allowUA = true;
}
}
All I want is that function to execute in strict order (changing variable to false, doing the loop and then changing variable back to true)
I found out that it's not as easy as it seems, so I ask for your help.
Is there a way to do this? Thanks in advance.