Jquery's tool functions encapsulate the processing methods of commonly used strings, numbers, arrays, and objects. Below are some of the commonly used methods:
String operation
| The code is as follows: |
Copy code |
Var str = 'www.111cn.net '; Console. log (str); // www.111cn.net Console. log ($. trim (str); // www.111cn.net, remove spaces $. Each view the data information of arrays and objects cyclically Var arr = ['It blog', 'php blog', 'javacsrip', 'net blog']; $. Each (arr, function (index, value ){ Console. log (index + '---' + value ); }); |
Output result: (the object method is the same as the array method)
0---IT Blog
1 --- php blog
2 --- Java SDK blog
3 --- net blog
$. Grep filtering information
| The code is as follows: |
Copy code |
Var arr = [, 34]; Var arr1 = $. grep (arr, function (element, index) {// element => array value size, index => index starts from 0... Return index <3; }); Console. log (arr1); // [4, 6, 3] |
$. Map returns the modified data
| The code is as follows: |
Copy code |
Var arr = [, 34]; Var arr1 = $. map (arr, function (element, index) {// element => array value size, index => index starts from 0... If (element> 5 & index <7 ){ Return element + 2; } }); Console. log (arr1); // [8, 90, 58, 80, 47] |
$. InArray: determines whether an element returns a subscript in an array.
| The code is as follows: |
Copy code |
Var arr = [, 34]; Console. log ($. inArray (88, arr); // 3: Find the subscript of an element in the array |
$. Merge arrays
| The code is as follows: |
Copy code |
Console. log ($. merge ([3, 5, 7], [5, 4, 2]); // [3, 5, 7, 5, 4, 2]: merge arrays |
Test function:
| The code is as follows: |
Copy code |
Console. log ($. isArray ([1, 2]); // true indicates whether an array is used. Console. log ($. isFunction (function aa () {}); // true determines whether the function is a function. Console. log ($. isEmptyObject ({}); // true determines whether an object is empty. Console. log ($. isPlainObject ({}); // true indicates whether the object is a pure object. Console. log ($. isPlainObject ({'name': 'A'}); // true determines whether the object is a pure object. Console. log ($. type (222); // number indicates the data type. Console. log ($. type ('20140901'); // string determines the data type Console. log ($. isNumeric (432); // true is not a number Console. log ($. isNumeric ('20140901'); // true is not a number Console. log ($. isWindow (window); // true indicates whether the window object is used. Console. log ($. contains ($ ('# box '). get (0), $ ('# pox '). get (0); // true, whether the box contains pox or not |
$. Browser detection
| The code is as follows: |
Copy code |
Console. log ($. browser. webkit); // You can check whether Google Chrome is used. Console. log ($. browser. mozilla); // You can check whether the Firefox browser is used. Console. log ($. browser. mise); // determines whether the browser is an IE browser. Console. log ($. browser. version); // judge the browser version |