0

There is code that processes Prestashop API response in NodeJS where async callback function needs to use values from the time it was called. How to pass orderRows and i to .then() function in code below?

var orderRows = [1,2,3,4];
for (var i = 0; i < orderRows.length; i++) {
    prestan.get('combinations', {"id": orderId}).then(function (combinationsResponse) {
    var s=orderRows[i];
Margus Pala
  • 8,433
  • 8
  • 42
  • 52
  • 1
    [JavaScript closure inside loops – simple practical example](https://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example) – Jonathan Lonowski Dec 04 '16 at 17:53
  • You can also use [`let i`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Cleaner_code_in_inner_functions) instead of `var i`. ([supporting versions](http://node.green/#let)) – Jonathan Lonowski Dec 04 '16 at 17:54
  • `let i` was the simplest solution. Thanks Jonathan! – Margus Pala Jan 09 '17 at 10:29

0 Answers0