title: How to get data from Firestore in map function
body: <p>I want to retrieve data from Firestore as I map through an object to see if the user is online. I'm not sure how to retrieve the data.  </p>
  
  <p>When I console.log userInLobby (as shown below), I get [Promise] array.</p>
  
  <p>If I try to set a variable before the firebase call, I cannot change the variable inside the .then() function</p>
  
  <pre><code> const userInLobby = users ? (
    users.map(userdata =&gt; {
      if (userdata.status === "online") {
        var user =
          firebase.firestore().collection("users").doc(userdata.id).get().then(user =&gt; {
            return { username: user.data().username };
          })
        return user
      }
      else {
        return null;
      }
    })
  ) : (null);
  </code></pre>
  
  <p>How can I access the [Promise] or is there another way to structure this code?</p>