I have this code in node js / firebase :
ref.child("recipts").once("value", function(usersSnap) {
usersSnap.forEach(function(reciptsSnap) {
reciptsSnap.forEach(function(reciptSnap) {
reciptSnap.ref.child("last_recipt").once("value", function(b) {
b.forEach(function(c) { //Here I fill some "product" object
});
});
reciptSnap.forEach(function(b) { //Here I fill some "product" object
});
});
});
});
I need to execute a function just when "reciptSnap" forEachs finished. How can I accomplish this, I try using a variable i++ and i-- but only work for one forEach iteration. The function I call is for manipulating the product object I created with the filled data from the forEachs loops.
firebase, but it doesn't seem strictly related to it. If the operations you run inside theforEachare async operations, then you can't do what you're trying to do in a proper way. The better way would be to use promises in an array, and execute them usingPromise.all(): developer.mozilla.org/en/docs/Web/JavaScript/Reference/…