javascript - Cannot use global variable in NodeJS MySQL -


i cannot access upcoming_matches array inside mysql query callback, how come?

i'm greeted 'typeerror: cannot read property '1' of null' error message on console.log(upcoming_matches[1]); line indicates variable being reset reason (a guess, i'm not experienced javascript)?

var regex = regex code..  while ((upcoming_matches = regex.exec(body)) != null) {     hltvid = upcoming_matches[1].split("-");          connection.query('select * `csgo_matches` hltvid=' + hltvid[0], function(err, rows, fields) {         if (err) throw err;         console.log(upcoming_matches[1]);     }); } 

because @ moment callback passed connection.query executed, while loop finished , upcoming_matches null (because that's condition while loop stop).

connection.query asynchronous.

see why variable unaltered after modify inside of function? - asynchronous code reference


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -