1,数组对象去重处理
this.json_sn = [{'institution_name':'GeeL',id:2} ,{'institution_name':'GeeL',id:3}, {'institution_name':'GeeLQ',id:4}]
var hash = {};
this.json_sn = this.json_sn.reduce(function (item, next) {
hash[next.institution_name] ? '' : hash[next.institution_name] = true && item.push(next);
return item;
}, [])
console.log('去重has',hash,this.json_sn)
2,javascript 判断某个数组中是否包含另一个数组
//是否被包含,是返回true,不是返回false
isContained =(a, b)=>{
if(!(a instanceof Array) || !(b instanceof Array)) return false;
if(a.length < b.length) return false;
var aStr = a.toString();
for(var i = 0, len = b.length; i < len; i++){
if(aStr.indexOf(b[i]) == -1) return false;
}
return true;
}
var a = [1,2,3,4,5];
var b = [1,4,3,2];
var c = [1,6];
alert(isContained(a,b)); //true
alert(isContained(a,c)); //false