If I use setTimeout in a loop so only after the loop ends it executes all the operation in the same time. I tried to put setTimeout in a separate function, as suggested by m