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