I have a function that clears two arrays and then populates them with values received from a mysql server.
function sqlget() {
var arrayA = [];
var arrayB = [];
con.query("SELECT * FROM table", function(err,result,fields) {
if (err) throw err;
Object.keys(result).forEach(function(key) {
arrayA.push(result[key].columnA);
arrayB.push(result[key].columnB);
});
});
}
What I would like to be able to do is then call arrayA/arrayB outside of function and have it return the sql information fetched inside the function with something such as...
sqlget()
console.log(arrayA)
Any advice for how this could be done would be much appreciated.