I have a set of firestore user id in an array object. How can i loop
over the array of userid and get each user username from firestore database. How can i achieve this using async await Java Script ES8
const array=["id1","id2",...]//array of ids
async function fetchData(){
array.map(id=>{
await fetch(<call to database using the id).then(res=>{//OK})
.catch(err=> {not ok})
})
}
Async await are a cleaner way to work with asynchronous functions like this.
0
votes
You can use async/await in loop as below.
const array=["id1","id2",...]
fetchData = () => {
array.forEach(async (id) => {
try {
await res = fetch(id)
// Do something with your res
} catch (err) {
console.log(err)
}
})
}
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more