简体   繁体   中英

How do I use loop in Firebase function?

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

在此处输入图像描述

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

Output should be like:

在此处输入图像描述

Try this;

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

if sampleDataSet is an object then we can loop object as well;

for (let [key, value] of Object.entries(sampleDataSet)) {
  console.log("Hello "  + value.firstName + " " + value.lastName);
}
database.ref("collection").once("value").then((snapshot) => { snapshot.forEach((userSnap) => { console.log('hello ' + userSnap.child(`firstName`).val() + ' ' + userSnap.child(`lastName`).val() ); }); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM