The following usage is recorded:
Jquery grep () filters and traverses Arrays
$ (). Ready ( Function (){ VaR Array = [1, 2, 3, 4, 5, 6, 7, 8, 9 ]; VaR Filterarray = $. grep (array, Function (Value ){ Return Value> 5; // Filter out more than 5 }); For (VaR I = 0; I <filterarray. length; I ++ ) {Alert (filterarray [I]);} For (Key In Filterarray) {alert (filterarray [Key]) ;}});
JqueryEach()Filter and traverse Arrays
$ (). Ready (Function(){VaRAnobject = {one: 1, two: 2, three: 3 };//For the JSON array each$. Each (anobject,Function(Name, value) {alert (name); alert (value );});VaRAnarray = ['one', 'two', 'three']; $. Each (anarray,Function(N, value) {alert (n); alert (value );});});
JqueryInarray()Filter and traverse Arrays
$ (). Ready (Function(){VaRAnarray = ['one', 'two', 'three'];VaRIndex =$. Inarray ('two', anarray); alert (INDEX );//Returns the key value of this value in the array, and returns 1Alert (anarray [Index]);//Value is two});
JqueryMap () filters and traverses Arrays
$ (). Ready ( Function (){ VaR Strings = ['0', '1', '2', '3', '4', 's', '6' ]; VaR Values = $. Map (strings, Function (Value ){ VaR Result = New Number (value ); Return Isnan (result )? Null : Result; // Isnan: Is Not A number abbreviation }); For (Key In Values) {alert (Values [Key]) ;}});
JqueryParse JSON object 1:
VaRJSON = [{DD: 'SB ', AA: 'dongdong', RE1: 123}, {CCCC: 'dd', lk: '1qw'}];For(VaRI = 0, L = JSON. length; I <L; I ++){For(VaRKeyInJSON [I]) {alert (Key+ ':'+ JSON [I] [Key]) ;}}
Jquery traverses and parses JSON object 2
// The following JSON object is available:VaROBJ = {"name": "Feng Juan", "Password": "123456", "department": "technology department", "sex": "female", "old": 30}; // Traversal method:For(VaRPInOBJ) {Str= STR + OBJ [p] +',';ReturnSTR ;}