SHARE
TWEET

Untitled

a guest Feb 17th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. doc.data() // For Each doc    
  2. Array[] // Filled with data and length 54
  3. Length: 54
  4.    
  5. Array[] // Filled with data and length 54
  6. Length: 0
  7. doc.data() // For Each doc
  8.    
  9. let exportArray = [];
  10. let promises = [];
  11.  
  12. db.collection('lists').doc('List 1').collection("members")
  13.     .get().then(function(querySnapshot) {
  14.     querySnapshot.forEach(function(doc) {
  15.         promises.push(
  16.             new Promise(function (resolve, reject) {
  17.                 exportArray.push(doc.data());
  18.                 resolve();
  19.                 console.log('before');
  20.             })
  21.         );
  22.     });
  23. });
  24.  
  25. Promise.all(promises).then(function () {
  26.     console.log(exportArray); // Logs correctly with all data with length 54
  27.     console.log(exportArray.length); // Logs as 0 for some reason
  28.  
  29.  
  30. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top