It allows you to iterate through the property values of an object, an array, and manipulate it.
Instructions for use
The each function does not have exactly the same effect as the type of the parameter:
1. Traversing objects (with additional parameters)
$.each (Object, function (P1, p2) {
This This here points to the current property value of the object in each traversal
P1; P2; Accessing additional parameters
}, [' Parameter 1 ', ' parameter 2 ']);
2. Iterating through an array (with attachment parameters)
$.each (Array, function (P1, p2) {
This This here points to the current element of the array in each traversal
P1; P2; Accessing additional parameters
}, [' Parameter 1 ', ' parameter 2 ']);
3. Traversing objects (no additional parameters)
$.each (Object, function (name, value) {
This This points to the value of the current property
Name Name indicates the current property of the object
Value Value that represents the current property of the object
});
4. Iterate through an array (no additional parameters)
$.each (Array, function (i, value) {
This This points to the current element
I I represents the array current subscript
Value Value represents the current element of the array
});
Here are some common uses of each of the jquery methods
JS Code
var arr = ["One", "one", "three", "four"];
$.each (arr, function () {
alert (this);
});
The results for each of the above outputs are: One,two,three,four
var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9]
$.each (arr1, function (I, item) {
Alert (item[0]);
});
In fact, ARR1 is a two-dimensional array, item is equivalent to taking each one-dimensional array,
Item[0] Relative to the first value in each one-dimensional array
So the above each output is: 1 4 7
var obj = {one:1, two:2, Three:3, four:4};
$.each (obj, function (key, Val) {
Alert (Obj[key]);
});
This each one is more powerful, can loop each property
The output is: 1 2 3 4
About the $each (Object, function (p1, p2) usage of jquery