Home > Article > Web Front-end > Examples of several common usage methods of jquery each_jquery
There are also many uses of each method in the jQuery source code. In fact, the each method in jQuery is implemented through the call method in js. The following is a brief introduction to the call method.
The call method is very wonderful. In fact, the official description is: "Call a method of an object and replace the current object with another object." More explanations on the Internet are to change the context environment, and some say to change the context this pointer.
The call method can be used to call a method on behalf of another object. The call method changes the object context of a function from the initial context to the new object specified by thisObj.
Example
Here are some common uses of jQuery’s each method
In fact, arr1 is a two-dimensional array, item is equivalent to taking each one-dimensional array,
item[0] is equivalent to taking the first value in each one-dimensional array
So the above each output They are: 1 4 7 { one:1, two:2, three:3, four:4};
$.each(obj, function(key, val) {
alert(obj[key]);