var errors = validationResult(req);
console.log("errors: errors");
if (!errors.isEmpty()) {
res.render('signIn-signUp', {
'error1': errors.msg + " " + errors.value + " Please signUp again!!"
});
} else {
var id = 0;
pool.query("Select Max(C_Id) as C_Id from customer", function(error, rows) {
if (error) {
console.log("Database error: ", error);
res.render('signIn-signUp', {
'error1': "database error: " + error + "please sign up again!"
});
The above code is part of a nodeJs codebase. In the above code snippet, when I log errors object on console, it shows all the properties as:
errors: [{
value: 'a',
msg: 'Must be at least 5 char long',
param: 'Password',
location: 'body'
}]
but, when I display the individual properties of the object on the console, it is showing it as undefined. That is, console.log(errors.msg) is returning undefined. What is the reason for that?
How can I display the properties which exist in the object and are not undefined?
It seems that the errors
object is an array (hence the []
). Try this:
console.log(errors[0].msg);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.