How break for each method

I’m dealing with a reservation system.ı use firebase realtime database. So I want to remove past data (historically, before today). I decided to use firebase functions for this.I try to use if else (I don’t know if there is an easier way) but I couldn’t use break and return commands. How can I stop this after deleting the days before today.

database structure :

exports.removePrev =
 functions.pubsub.schedule("every 5 minutes").onRun((context) => {
   const day = new Date();
   const targetDateFormat = new Date(day).toLocaleDateString("en-US", {
     year: "numeric",
     month: "2-digit",
     day: "2-digit"});
   const resultDay = targetDateFormat.replace(/[/]/g, "-");
       if (days.key != resultDay) {
       } else if (days.key==resultDay) {
         //Want to break;
   return null;


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

forEach does not support break, check this answer
Short circuit Array.forEach like calling break

alternatively you can use for of , MDN Docs:…of

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x