.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
//没有该方法时,自定义 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' });