I am stumped.
I have successfully retrieved an array of objects from a mySQL database using NodeJS:
console.log('The clientData array: \n',clientData);
returns:
Array (2)
0: RowDataPacket {clientID: 1, nfpStatus: 0, companyName: "Enron"}
1: RowDataPacket {clientID: 2, nfpStatus: 0, companyName: "Goldman Sachs"}
From the same scope as this console log call, I've tried to use several methods to walk through the array, but always it returns nothing. Zero. Zip. Zilch. There is no result, and there is no error.
Here are some of those methods:
$(clientData).each(function(index,values){ // what I would normally do
console.log(index,values);
});
$.each(clientData, function(index,values){
console.log(index,values);
});
clientData.forEach(function (index,values) {
console.log(index,values);
});
clientData.forEach((index,values)=>{ // getting desperate now...
console.log(index,values);
});
Any thoughts? Let me know if you require more information.
Here is the original MySql query, requested by Adam:
var clientData = Array(); // make global
connection.connect((err) => {
if(err) throw err;
connection.query('SELECT * FROM clients JOIN address ON clients.clientID = address.clientID', (err, rows, fields) => {
if(err) throw err;
$.each(rows, function(index, values){
clientData.push(values);
});
connection.end();
});
});
// my console.log call and foreach both fall in the global scope as well