有人可以向我解释为什么数组(定义在函数之外)没有被函数填充。所以我可以将它用于其他功能
我的代码:
var points = [];
var eilutes = [];
var query = connection.query('SELECT * FROM ping', function(err, eilutes){
//if (err) throw err;
for (var i in eilutes){
points.push(eilutes[i]);
}
console.log(points[1]); //// Result is returned
console.log(eilutes[1]); //// Result is returned
});
console.log(points[1]); //// promts: undefined
console.log(eilutes[1]); //// promts: undefined