node.js - FOR LOOP in Node js needing the result of the previous iteration -


i need loop in node js need result of previous iteration.

function jsonparser(txt_file, cb) { var perc = 0;  lines = txt_file.split('\n');  insert_communication = 'insert communication (account_id, contact_id, type_com_id, coin_id, com_datetime, ' +     'destination_key, destination_st, duration, cost, description, discount)  values ';  insert_internet = 'insert internet_data (account_id, contact_id, type_com_id, coin_id, com_datetime, ' +     'duration, cost, description, discount)  values ';  (let = 2; < lines.length; i++) {      readtextfile2(lines[i], function (cb) {         if (cb[0] == "communication")             insert_communication += cb[1] + ',';         if (cb[0] == "internet")             insert_internet += cb[1] + ',';       });         }  cb(insert_communication); 

}

how supposed achieve this?

thanks

  (let = 2; < lines.length; i++) {          const previous = lines[i - 1 ];         const hasprevious = !!previous;          if(hasprevious) {              //ok have value, use          }          readtextfile2(lines[i], function (cb) {               if (cb[0] == "communication")                     insert_communication += cb[1] + ',';               if (cb[0] == "internet")                     insert_internet += cb[1] + ',';           });   } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -