0
   var statusArray = new Array();

   statusArray.forEach(function (item) {                
                 if (checkStatus != item) {
                     disableall = true;
                     return false;
                }
             });

I am returning false but not able break from foreach loop.

PeeHaa
  • 69,318
  • 57
  • 185
  • 258
Sagar K
  • 1,027
  • 2
  • 23
  • 49
  • Possible solution for you http://stackoverflow.com/questions/2641347/how-to-short-circuit-array-foreach-like-calling-break – Pavlo Feb 14 '14 at 08:15

1 Answers1

1

There is no way to do break a forEach() loop

Note : There is no way to stop or break a forEach loop. The solution is to use Array.every or Array.some. See example below.

Since you have tagged it using jQuery, use $.each() if possible

var statusArray = new Array();

$.each(statusArray, function (i, item) {
    if (checkStatus != item) {
        disableall = true;
        return false;
    }
});

Else try Array.every()/Array.some() as given in MDN

Arun P Johny
  • 376,738
  • 64
  • 519
  • 520