jquery筛选数组方法——$.grep(),$.map()

 

 

        function greptest() {
            var arr = "1,2,3,'',one,two,three".split(',');

            var newarr = $.grep(arr, function (num, ind) {
                return isNaN(num);      //两个方法之间的差别
            });
            console.log(newarr);
        }
        function maptest() {
            var arr = "1,2,3,'',one,two,three".split(',');

            var newarr = $.map(arr, function (num, ind) {
                return isNaN(num) ? num:null;    //两个方法之间的差别
            });
            console.log(newarr);
        }

 

posted @ 2015-07-03 17:23  stevejson  阅读(506)  评论(0编辑  收藏  举报