Sunday, October 5, 2025
Latest:
  • German Pronouns with Nominative, Accusative, and Dative cases
  • German articles for the nominative, accusative, and dative cases
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

How to do break from a forEach loop JavaScript?

Published: March 7, 2021 break, forEach loop

There is no way to stop or break a forEach() loop. We can stop or break it by throwing an exception. Following is an example of doing stop or break inside forEach:

   const carBrand = ['BMW', 'Audi', 'Toyota', 'Tesla', 'TATA'];
   const breakException = {};

   try {
       carBrand.forEach((item) => {
           console.log(item);
           if (item === 'Audi') throw breakException;
       });
   } catch (e) {
       if (e !== breakException) throw e;
   }

You May Also Like

Fatal error: Uncaught Error: [] operator not supported for strings

May 15, 2019 beroza

In which order static initialisation block and constructor run in java?

September 16, 2019 beroza

Find First and Last Position of Element in Sorted Array

January 29, 2023 beroza

How to get system properties or environment variables in spring thymeleaf template?

February 27, 2019 beroza

What is pseudo element ::before and ::after in CSS?

May 9, 2019 beroza

What is microservice? What are the properties of microservice?

June 18, 2020 beroza

The following PHP extension is missing: curl AMP WordPress

January 16, 2020 beroza

What is an arrow function and why use arrow function in JavaScript?

March 18, 2019 beroza

CSS special selectors

August 26, 2021 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2025 Upokary. All rights reserved.