Skip to content Skip to sidebar Skip to footer

Why I Get Undefined Email Data Result From FindAll Sequelize?

Please help, how to show email from Sequelize findAll query, because i get Undefined from my source code, can some body help me ? Here my code testdata.get = (req, res) => { U

Solution 1:

It is because .findAll() method returns an array, not a single object which you can access by the dot notation .email. Refer to .findAll() docs.

testdata.get = (req, res) => {
  User.findAll()
    .then(data => {

        data.forEach((object) => console.log(object.email));

    })
    .catch(err => {
       res.json({
       message: (err, "Error")
    });
  });
  return;
};

Solution 2:

I think the data will be an array of objects and not just an object.

So I suggest you log data first and then loop through that and check if it contains the email key.


Post a Comment for "Why I Get Undefined Email Data Result From FindAll Sequelize?"