The three functions available in jquery: Map,each,trim
$.map (Arry,callback (Element,index));
For each element in an array of arrays, call the callback () function and eventually return a new array. The original array does not change.
Source
arg is for internal usage onlymap: function ( elems, callback, arg ) {var length, value,i = 0,ret = [];// go through the array, translating each of the items to their new valuesif ( isarraylike ( elems ) ) {length = elems.length;for ( ; i < length; i++ ) {value = callback ( elems[ i ], i, arg );if ( value != null ) {ret.push ( value );}} Go through every key on the object,} else {for ( i in elems ) {value = callback ( elems[ i ], i, arg );if ( value != null ) {ret.push ( value );}} flatten any nested arraysreturn concat.apply ( [], ret );}
$.each (ARRAY,FN); iterating over an array
Used primarily to iterate through an array without modifying the array. There is no problem with either an ordinary array or a "key-value pair" array.
return False to exit the loop
You can use this directly in the each function to represent the value of the current element.
Source
Each:function (obj, callback) {var length, i = 0;if (isarraylike (obj)) {length = Obj.length;for (; i < length; I + +) {if (Callback.call (obj[i], I, obj[i] = = = = False) {break;}}} else {for (i in obj) {if (Callback.call (obj[i], I, obj[i]) = = = False) {break;}}} return obj;}
Sample code
<! doctype html public "-//w3c//dtd html 4.01 transitional//en" "HTTP// Www.w3.org/TR/html4/loose.dtd ">650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/86/AB/wKiom1fHLKXzIiavAAENCkHou7w723.gif "title=" jquery _each.gif "alt=" Wkiom1fhlkxziiavaaenckhou7w723.gif "/>
Case: Using arguments objects to test the parameters needed in a method
Test Map method
<! doctype html public "-//w3c//dtd html 4.01 transitional//en" "HTTP// Www.w3.org/TR/html4/loose.dtd ">650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/86/AB/wKiom1fHLeHChzDvAAP55bCh4Vs486.gif "title=" jquery _map_arguments.gif "alt=" Wkiom1fhlehchzdvaap55bch4vs486.gif "/>
Test each method
<! doctype html public "-//w3c//dtd html 4.01 transitional//en" "HTTP// Www.w3.org/TR/html4/loose.dtd ">650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/AB/wKioL1fHLmGwHD88AAG_M8aeY4I775.gif "title=" jquery _each_arguments.gif "alt=" Wkiol1fhlmgwhd88aag_m8aey4i775.gif "/>
Doubles the elements in an array and returns a new array
<! doctype html public "-//w3c//dtd html 4.01 transitional//en" "HTTP// Www.w3.org/TR/html4/loose.dtd ">650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/86/AB/wKioL1fHL8bTKwyTAAFdWEkbFWU187.gif "title=" jquery _map_eg.gif "alt=" Wkiol1fhl8btkwytaafdwekbfwu187.gif "/>
Doubles the value of an element in an array that is greater than 3, the remaining value is unchanged, and returns the array
<! doctype html public "-//w3c//dtd html 4.01 transitional//en" "HTTP// Www.w3.org/TR/html4/loose.dtd ">650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/AB/wKioL1fHMFGQvDvwAAFuZG0aO-4373.gif "title=" jquery _map_eg2.gif "alt=" Wkiol1fhmfgqvdvwaafuzg0ao-4373.gif "/>
$.trim (str);
Remove both spaces and debug to see how it is implemented
Source
RTrim =/^[\s\ufeff\xa0]+| [\s\ufeff\xa0]+$/gtrim:function (text) {return text = = null? "":(text + ""). Replace (RTrim, "");
Essentially similar to str.replace (/^\s+/, ");
trimleft=/^[\s\xa0]/;
trimright=/[\s\xa0]+$/;
Some versions of IE do not support \s spaces, \xa0 also indicate spaces
The three functions available in jquery: Map,each,trim