0
const chatdb = db.collection("users").get();
chatdb.then((snapshot) => {
  return snapshot.docs.map((doc) => {
    if (doc.data().email == userEmail) {
      return { name: doc.data().name, image: doc.data().image };
    }
  });
});
console.log(chatdb);

Here, chatdb is returning Promise{<pending>}, I dont know why, I am just learning the concept of promises and I tried many ways to return the object but everytime it returned as a promise.

I just need to log the object that I returned in the map function

How to access the value of a promise? this doesn't helps

Shubham Singhvi
  • 304
  • 1
  • 10
  • You cannot get anything else right now but a promise for the future value. You must do the logging later, when the value is available - so just move the `console.log` statement inside the `then` callback – Bergi Jul 28 '22 at 17:01
  • @Bergi yeah I got the value in log statment but I want it to be reusable for assigning values – Shubham Singhvi Jul 28 '22 at 17:36
  • No you don't. You put all code using it in the `then` callback. What else do you need it for other than logging? – Bergi Jul 28 '22 at 17:38
  • @Bergi Do you have a solution ? – Shubham Singhvi Jul 28 '22 at 17:40
  • 1
    The solution is to put the code that needs the "assigned values" inside the callback. If you need help with that, please [edit] your question to show that code, and explain why you think you can't put it inside the callback. – Bergi Jul 28 '22 at 20:41
  • @Bergi thanks, just didn't got that earlier – Shubham Singhvi Jul 29 '22 at 02:22

0 Answers0