代码:
var email = req.body.email
var sql = 'Select password FROM user where email = ' + mysql.escape(email)
con.query(sql, (err, rows, fields) => {
if (!err) {
res.send(rows)
var result = Object.values(JSON.parse(JSON.stringify(rows)))
console.log(result)
} else console.log(err)
})
在这里,当我打印"结果"变量时,我可以得到如下的输出
[{ password: '123' }]
如何获取另一个变量的密码值(示例:x=123(
您的密码作为对象存储在数组的第一个单元格中,因此:
var result = [{ password: '123' }];
var x = result[0].password; //Get the password value of the object in the first cell of the array
console.log('Result = ' + JSON.stringify(result));
console.log('x = ' + x);