Home > database >  How do I use loop in Firebase function?
How do I use loop in Firebase function?

Time:10-05

I want to run loop in Firebase function sample data set:

enter image description here

I want to loop through it and print console.log hello

Output should be like:

enter image description here

CodePudding user response:

Try this;

 sampleDataSet.forEach((d)=>{
  console.log("Hello "    d.firstName   " "   d.lastName);
})

CodePudding user response:

database.ref("collection").once("value").then((snapshot) => {
    snapshot.forEach((userSnap) => {
        console.log('hello '   userSnap.child(`firstName`).val()   ' '   userSnap.child(`lastName`).val() );
        });
  });
  • Related