9

how can I abort the jquery each function?

$.each(big_test_object, function(i)
{
   // some code

});
Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
Peter
  • 11,413
  • 31
  • 100
  • 152
  • Possible duplicate of [How to break out of jQuery each Loop](https://stackoverflow.com/questions/1784780/how-to-break-out-of-jquery-each-loop) – Bob Stein May 30 '17 at 17:34

2 Answers2

20

from the jquery each documentation

We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.

$.each(big_test_object, function(i)
{

   if(i == 'yourvalue') {
          return false;
   }

});
Tim
  • 9,351
  • 1
  • 32
  • 48
2

you should return false in your callback

cheers

Pedro Gil
  • 532
  • 2
  • 7
  • 18