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
  • 71,436
  • 58
  • 190
  • 262
S2K
  • 1,185
  • 3
  • 27
  • 55
  • 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
  • 384,651
  • 66
  • 527
  • 531