JavaScript Synchronous Loops

I hit my head about JavaScript asynchronous behavior when scaling functions from my test data to production work.

Do I have a loop forthat, as I know, will range from hundreds of thousands, will Node pause the loop forand return to it, or can I safely assume that Node will execute the loop to complete before returning my function?

Here is the cycle in question:

function fixData(dataset, blockcount){
  for (var i = 0, len = dataset.length; i < len; i++) {
    var obj = dataset[i];
    obj._id = obj.name;
    obj.expires = blockcount + obj.expires_in;
    delete obj.expires_in;
  }
  return dataset;
}
+4
source share
2 answers

Node.js JavaScript, . , , , .

+9

for of for in

for(const elment of arrayElements) {
            await yourFunc(elment)
            await yourOtherFunc('somePatameter')
}
-1

Source: https://habr.com/ru/post/1540995/


All Articles