This article introduces the very useful traversal functions each and map functions in jQuery, and compares the usage methods of these two functions. I believe this is very helpful to everyone, for more information about the coders, see.
Each usage
1. each in the array
Var arr = ["one", "two", "three", "four"]; $. each (arr, function () {alert (this) ;}); // The above each Outputs 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, and item is equivalent to taking every one-dimensional array, // item [0] is relative to the first value in each one-dimensional array. // The above each output is: 1 4 7 var obj = {one: 1, two: 2, three: 3, four: 4}; $. each (obj, function (I) {alert (obj [I]) ;}); // This each is more powerful and can loop through every attribute. // The output result is: 1 2 3 4
2. Traverse Dom elements