Native JS uses foreach () and jquery to use each () to traverse the array, the difference of return false:
1. Use each () to traverse array A, as follows:
var a=[20,21,22,23,24];
$.each (A, function (index,val) {
console.log (' index= ' +index);
if (index==2) {return
false;
}
Console.log (' val= ' +val);
The results are as follows:
From the effect of the operation can be seen, return is equivalent to the break in the loop, directly end the entire loop.
2. Use foreach () to traverse array A, as follows:
var a=[20,21,22,23,24];
A.foreach (function (val,index) {
console.log (' index= ' +index);
if (index==2) {return
false;
}
Console.log (' val= ' +val);
The results are as follows:
From the effect of the operation can be seen, return is equivalent to the continue in the loop, out of the current loop, followed by the loop traversal continues.
I have also looked at some of the data, and we can end the whole foreach () loop by writing our own judgment statements, or iterate over it using a for () loop.