I'm implementing some function in which retrieves some data of type array from firebase, then search for specific element from that array and if exists, I would like to abort the function and return back to the caller. (React-native app)
here is the Code:
ref.get().then(snapshot => { const personArr = snapshot.data().winPerson; ... if (personArr != undefined) { personArr.forEach(item => { if (item == uid.uid) { alert(`already subscribed`); return; } }); if (prop.first.length != 0) { uploadHelper(ref, prop, "first"); } ... } }); I loop through the array using forEach and see if there is matching element. If there is match, then it should alert and return to the caller function without running the subsequent code below, which is
if (prop.first.length != 0) { uploadHelper(ref, prop, "first"); } However, assuming that the element does exist in the array, the code runs both alert and the uploadHelper function(checked through log). First I thought forEach was async function so uploadHelper executed before the return; however, forEach is not async function (after some googling).
I have no idea why uploadHelper runs if the code falls into the if (item == uid.uid) condition and returns.
any help is appreciated. Thank you