The source data is an array when the form is validated, and if one fails, the loop is broken

But forEach does not break out of the loop by using a return

ForEach breaks out of the loop:

For forEach, filter,map loops, try catch is used

Or use for,some,every instead

ForEach returns an error if a break is used (filter,map) and a return does not break the loop

Because all three methods are functions

try { var array = ["first", "second", "third", "fourth"]; array.forEach(function (item, index) { if (item == "third") { throw new Error("ending"); } else {console.log(item); {if}})} the catch (e) (e.m essage = = "ending") {the console. The log (" jump out of the loop..." ); Var arr = [1, 2, 3, 4, 5]; var arr = [1, 2, 3, 4, 5]; var num = 3; arr.some(function (v) { if (v == num) { return true; } console.log(v); }); Var arr = [1, 2, 3, 4, 5]; var num = 3; arr.every(function (v) { if (v == num) { return false; } else { console.log(v); return true; }});Copy the code