I am currently running a forEach loop like bellow:
snapshot.forEach((theChild) =>
let newPostID1 = String(snapshoot.key);
let newUID = String(child.key);
//Spill coffee here.
})
ForEach loops do not allow you to exit after a condition is met.
What is an alternative method of looping through my snapshot which allows me to return (exit) after a condition is met?
You can use val() to get a JavaScript object with the entire set of data at the snapshot. Then you can iterate its keys using standard JavaScript object property iteration with for..in and break whenever you want.
const val = snapshot.val()
for (const key in val) {
console.log(`child key: ${key}`)
console.log(`child value: ${val[key]}`)
// break whenever you want
}