The first is map,
Syntax: $.map (ARR,FUNC);//functin (Ele,i)
Note that the rollback function is a parameter, and the index and value of the array object that represents the loop
The goal is to turn the process operation into a functional operation
Function: Use the back function to process elements in each array or object and return a new one
For example, double the number of values in the array that are greater than 3
var arr = [One,
A, a, a, a, a, a, a. var New_arr = $.map (arr, function (V, i) {
return v * (i% 2 = = 0? 1:2);
});
alert (New_arr);
followed by each loop:
Syntax: $.each (COLLECTION,FUNC);//function (K,V)
Note that the parameters of the callback function are the keys and values of each member
The function is to iterate over an object or an array, noting that nothing is returned
If you need to stop the traversal, use return false;
Example:
var o = {name: "Xiaoming", age:19, Sex: "Male"};
$.each (o, function (k, v) {
Console.log (k + "--" + V);
});
The basic idea of the map loop and each loop is to turn the procedure-oriented operation into a functional operation. Convenient for chained programming (functional programming)