I need loop into an object array sending chunks to a server to store in database. like this simplified example:
(async function () {
var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var i, j, block, chunk = 3;
for (i=0, j=array.length; i<j; i+=chunk) {
block = array.slice(i,i+chunk);
console.dir(block);
//Some async promise to do the magic
}
})();
The problem is that in nodejs, traditional for loop doesn't works asynchronous. This other loop works fine:
(async function () {
for (const element of rows) {
//Some async promise
}
})();
How could I convert the first loop in chunks like the second one that works? are any other better sintax to do the same?