P粉2450036072023-08-22 14:50:44
The return statement return
will exit the current function, but the loop will continue, so you will get the "next" skipped if
statement and pop 4 Item...
If you need to stop the loop, you should use a normal for
loop like this:
$('button').click(function () { var arr = [1, 2, 3, 4, 5]; for(var i = 0; i < arr.length; i++) { var n = arr[i]; if (n == 3) { break; } alert(n); }) })
You can read more about break and continue in js here: http://www.w3schools.com/js/js_break.asp