Waiting for Promise before moving to next iteration in a loop in Node.js

前端 未结 3 501
醉梦人生
醉梦人生 2020-12-21 11:10

I have the following loop in node.js

for (var i in details) {
  if (!details[i].AmntRcvd > 0) {
    res.sendStatus(400);
    return;
  }

  totalReceived          


        
3条回答
  •  半阙折子戏
    2020-12-21 11:55

    You can use async library for this.then go for async.eachSeries.

    You need to do npm install async first

    Here is the example:

    var async = require('async');
    async.eachSeries(yourarray,function(eachitem,next){
    // Do what you want to do with every for loop element
    next();
    },function (){
    //Do anything after complete of for loop
    })
    

提交回复
热议问题