Guest User

Untitled

a guest
Feb 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  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. });
Add Comment
Please, Sign In to add comment