How can I make the value return outside the onSnapshot function?
function checkIfExisting(){
const collection = firebase.firestore().collection("audit");
const getCaseID = collection.where("caseID", "==", "00001234");
getCaseID.onSnapshot(function(querySnapshot) {
let wordLists = [];
querySnapshot.forEach(function(doc) {
//get all the scanned words under "word" field in the Firestore Database
wordLists.push(doc.data().word);
});
console.log("words: ", wordLists);// return a value
});
console.log("words1: ", wordLists);// undefined
}
I knew that the console.log("words1: ", wordLists)
is outside the function that's why I can't get its value. Could you please give me an idea on how can I call it outside the function (if possible).