Copy codeThe Code is as follows:
Var arr1 = ["one", "two", "three", "four", "five"];
$. Each (arr1, function (){
Alert (this );
});
Output: one two three four five
Copy codeThe Code is as follows:
Var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]
$. Each (arr2, function (I, item) {parameter names can be defined by yourself. The each method judges 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 codeThe Code is 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 codeThe Code is as follows:
$. Each ($ ("input: hidden"), function (){
Alert (this. name );
});
$. Each ($ ("input: hidden"), function (){
Alert (this. value );
});
Hop out Traversal
Copy codeThe Code is 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;
}
Alert ('index' + I + '_' + item [0]);
});
})