JQuery provides two functions:
1. $. map (array, callback (element, index ));
For each element in the array, call the callback () function and return a new array. The original array remains unchanged.
For example:
$ (Function (){
Var arrInt = [1, 3, 5, 79];
Var B = $. map (arrInt, function (value, key, a) {// map returns a new array.
Return value * 2;
});
})
2. $. each (array, fn );
It is mainly used to traverse the array without modifying the array. It can traverse common arrays or "key-value pairs.
You can use this directly in the each function to represent the value of the current element.
For example, retrieve the selected items in the checkbox
<Script type = "text/javascript">
$ (Function (){
Var arr = [];
$ ('Input [type = checkbox] '). click (function (){
$ ('Input [type = checbox]: checked'). each (function (key, value ){
Arr [key] = value. text ();
});
Var lengtha = $ ('input [type = checkbox] [checked = checked] '). length; $ ('# spMsg '). text ('Total' + lengtha + 'is selected:' + arr );
})
})