Copy Code code as follows:
var arr1 = ["One", "two", "three", "four", "five"];
$.each (arr1, function () {
alert (this);
});
Output: One two three four five
Copy Code code as follows:
var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
$.each (arr2, function (I, item) {The name of the parameter can be defined by itself, each method will judge the correctness of the callback function method body syntax based on the format of the first parameter (ARR2)
Alert (item[0]);
});
Output: 1 4 7
Copy Code code as follows:
var obj = {one:1, two:2, Three:3, Four:4, five:5};
$.each (obj, function (key, Val) {
Alert (Obj[key]);
});
Output: 1 2 3 4 5
Copy Code code as follows:
$.each ($ ("Input:hidden"), function () {
alert (this.name);
});
$.each ($ ("Input:hidden"), function () {
alert (this.value);
});
Jump out of the loop
Copy Code code as follows:
$ (document). Ready (
function test ()
{var index=0;
var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9]]
$.each (arr1, function (I,item) {
if (i==1)
{
Alert ("Click to continue next traversal");
return; return false; jump out of the loop
}
Alert (' Index ' +i+ ' _ ' +item[0]);
});
})