Jquery everyone leaves earlier

I have a jQuery for-each loop in an array and am wondering if it is possible to exit the loop earlier.

  $ (lines) .each (function (i) {  
     // some code  
     if (condition) {  
         // I need something like break;  
     }  
 }); 

break; not really working for some reason.

If I wrote a for loop, it would look like this (but I don't want it):

  for (i = 0; i <lines.length; i ++) {  
     // some code  
     if (condition) {  
         break;  // leave the loop 
     }  
 }; 

Thanks in advance -Martin

+4
source share
2 answers

According to docs :

If you want to break each () loop at a specific iteration, you can do this by returning a false function. The non-false return is the same as the continue statement in the for loop; it immediately proceeds to the next iteration.

+12
source

Returns boolean false
(SEE http://docs.jquery.com/Utilities/jQuery.each , fourth paragraph)

 $(lines).each(function(i){ // some code if(condition){ // I need something like break; return false; } }); 
+4
source

All Articles