Possible Duplicate:
How do I break out of an $.each in jquery?
How to quit the jquery $.each loop?
Use return false inside the .each() loop to break out entirely. Returning anything that's not false is like continue: it stops the current iteration and jumps right to the next.
var myArr = [1,2,3,4,5,6,7];
$.each( myArr, function(){
  // Skip on three
  if( this === 3 ) return true;
  // Abort on five
  if( this === 5 ) return false;
  doStuff( this ); // never for 3, 5, 6 or 7
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With