Im having issues with accessing the value of a variable in NodeJS. Here is some example code and the results I get.
for (var z=0, zMessageCount = Description.length; z<zMessageCount; z++){
console.log(z);
if(SomeOtherColumnValue[z] > 9){
client.query('SELECT * FROM my_table WHERE some_column=' + ColumnValue[z], function (err, results) {
if(results < 1){
console.log(z);
}
})
}
}
Here is the issue I am having. In for “for” loop the value of z is going from 0 to 14. However when I try to access it from the client.query function its value is 15. It is not adding 1 to itself for every loop. Is there something I am missing here?
You need to wrap z in a function to provide scope.