• JQuery解析json对象、遍历筛选数组



    jquery grep()筛选遍历数组
    $().ready(
       function(){
           var array = [1,2,3,4,5,6,7,8,9];
           var filterarray = $.grep(array,function(value){
               return value > 5;//筛选出大于5的
           });
           for(var i=0;i<filterarray.length;i++){
               alert(filterarray[i]);
           }
           for (key in filterarray){
               alert(filterarray[key]);
           }
       }
    );

     

    jquery each()筛选遍历数组
    $().ready(
       function(){
           var anObject = {one:1,two:2,three:3};//对json数组each
           $.each(anObject,function(name,value) {
               alert(name);
               alert(value);
           });
           var anArray = ['one','two','three'];
           $.each(anArray,function(n,value){
               alert(n);
               alert(value);
           }
           );
       }
    );

     

    jquery inArray()筛选遍历数组
    $().ready(
       function(){
           var anArray = ['one','two','three'];
           var index = $.inArray(‘two’,anArray);
           alert(index);//返回该值在数组中的键值,返回1
           alert(anArray[index]);//value is two
       }
    );

    jquery map()筛选遍历数组

    $().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的缩


               }
           );
           for (key in values) {
               alert(values[key]);
           }
       }
    );

     

    jquery遍历解析json对象1:
    var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}];
    for(var i=0,l=json.length;i<l;i++){
       for(var key in json[i]){
           alert(key+’:'+json[i][key]);
       }
    }

    jquery遍历解析json对象2
    有如下 json对象:
    var obj ={”name”:”冯娟”,”password”:”123456″,”department”:”技术部”,

    ”sex”:” 女”,”old”:30};
    遍历方法:
    for(var p in obj){
       str = str+obj[p]+’,’;
       return str;
    }

  • 相关阅读:
    安卓5.1/7.1/8.1+wifi有叉问题解决
    历史市盈率查询
    IE9 Windows7 x64
    Error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
    ubuntu kylin 13.10 无法安装ia32-libs解决方案
    ajax报错问题的解决
    关于 java swing 使用按钮关闭窗口
    关于在filter中获取WebApplicationContext的实践
    spring security
    毕设项目,系统搭建笔记文档
  • 原文地址:https://www.cnblogs.com/star2012/p/2771593.html
Copyright © 2020-2023  润新知