我是node的新手,我想把mysql查询的结果作为数组返回。
这是我的代码:
function alterObject(obj) {
var c = [];
con.query("SELECT KeyName FROM SearchKeyWord", function(err, rows, field) {
for (var i in rows) {
c = c + rows[i].KeyName + "'" + "," + "'";
}
c = c.substring(0, c.length - 2);
console.log(c)
});
obj.foo = c;
}
alterObject(myObj);
console.log(myObj.foo);