I'm creating a while loop to cycle through an object array and depending on the info inside them, a MySQL transaction is executed. But, the conditional statement containing the MySQL transaction is not executed until the end of the while loop.
var objectArray = [ { id: 1, item: 4, rate: 1 }, { id: 2, item: 5, rate: 1 } ];
var d = 0;
while (d < objectArray.length) {
var rate1 = objectArray[d].rate;
console.log(objectArray[d].item);
if (rate1 > 0.5) {
console.log('step 1');
// perform mysql transaction
}
d++;
}
The console logs show "4" and then "5" and then shows "step 1" twice. What it should show is "4" then "step 1" and then "5" then "step 1".