Jquery array traversal how to get out of the current each loop

  • 2020-03-30 03:14:16
  • OfStack

Recently in the busy official website revision, in doing one of the projects encountered a small problem. The problem is, jquery's looping method does array traversal, but when the conditions do not meet, how to jump out of the current loop.

I was looping through the array using $.each(), but when I came to judgment, it wasn't clear how to get out of the loop, so I used the javascript method, continue, to find that it wasn't correct. The instructions on the API simply jump out of the loop (if you need to exit each loop, the callback function returns false, and other return values are ignored).

Later, I checked the Internet and got the result:

Return false; -- break out of all cycles; This is equivalent to the break effect in javascript.

Return true; -- jump out of the current cycle and enter the next cycle; Equivalent to the continue effect in javascript.

PS: for those who are just starting to learn jquery.

Related articles: