js .filter/.find不兼容ie


.filter:

https://blog.csdn.net/weixin_30784945/article/details/95575670

Array.prototype.myfilter = function(fun /*, thisp*/){  
    var len = this.length;  
    if (typeof fun != "function"){  
        throw new TypeError();  
    }  
    var res = new Array();  
    var thisp = arguments[1];  
    for (var i = 0; i < len; i++){  
        if (i in this){  
            var val = this[i]; // in case fun mutates this  
            if (fun.call(thisp, val, i, this)) {  
                res.push(val);  
            }  
        }  
    }  
    return res;  
}; 

var tina = ArrData.myfilter(function(item, inde, array){
    return item.mapid == 5; //过滤条件,根据自己需求修改
  })

  .find

https://www.cnblogs.com/huangtailang/p/7273980.html

//没有该方法时,自定义
if(!Array.prototype.find){
    Array.prototype.find = function(callback) {
        return callback && (this.filter(callback)|| [])[0];
    };
}

//demo
var s = [{"name":"001"},{"name":"002"},{"name":"003"}];
s.find(function(a){
  return a.name=='001'
});

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM