JavaScript jumps out of the loop in general with a break.
Colleagues encountered this problem, subconsciously used the break, want to jump out of this cycle. Result error
Syntaxerror:unlabeled break must be inside loop or switch
After investigation, should use a
Return False in the callback function, which is true of most JQ methods.
The code is as follows:
returning ' false ' will stop the loop (like using ' break ' in an ordinary loop).
Returns ' true ' to the next loop (like using ' Continue ' in an ordinary loop).
jquery jumps out of each loop instance
| The code is as follows |
Copy Code |
var arr = ["abc", "EF", "gggg"]; $.each (arr, function (index, value) { If (This = = "abc") return false; } ); |
jquery returns false; just jump out of the loop ~ do you want to return the value or do it outside the loop?
The code is as follows
| The code is as follows |
Copy Code |
function Test () { var success = false; $(..). each (function () { If (..) { Success = true; return false; } }); return success; } |
Related tutorials: Simple analysis of jquery each () Method usage and optimization