Home >Web Front-end >JS Tutorial >How to jump out of the current each loop for array traversal in jquery_jquery

How to jump out of the current each loop for array traversal in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 16:45:481283browse

Recently, I have been busy revamping the official website, and encountered a small problem while working on one of the projects. The problem is this, array traversal is performed through jquery's loop method, but when the conditions are not met, how to break out of the current loop.

I used $.each() to loop through the array, but when entering the judgment, I didn’t know how to get out of the current loop, so I used the javascript method - continue and found that it was incorrect. The instructions on the API can only jump out of the entire loop (if you need to exit each loop, the callback function can return false, and other return values ​​​​will be ignored.)

Later I checked online and got the result:

return false;——Jump out of all loops; equivalent to the break effect in JavaScript.

return true;——Jump out of the current loop and enter the next loop; equivalent to the continue effect in javascript.

PS: Share it with those who have just started learning jquery.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn