Jquery provides two functions:
1. $. Map (array, callback (element, index ));
For each element in the array, call the callback () function to 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 );
})
})