es6
let arr1 = [{id:'1',name:'json'},{id:'2',name:'book'} ]
let arr2 = [{id:'1',name:'json',age:'15'},{id:'2',name:'book',age:'16'},{id:'3',name:'ani',age:'17'}]
//ES6的方法
let add = arr2.filter(item => !arr1.some(ele=>ele.id===item.id));
比如
//删除
remove(data){
this.checkedNodes=this.checkedNodes.filter( item=>{
return !(data.orgCode===item.orgCode)
});
}
es5
/ES5的方法
for (var i=0; i<arr2.length; i++) {
for (var j=0; j<arr1.length; j++) {
if (arr2[i].id == arr1[j].id) {
arr2.splice(i, 1);
}
}
}
//es5删除
//删除
remove(data){
for (let i=0; i<this.checkedNodes.length; i++) {
if (data.orgCode== this.checkedNodes[i].orgCode) {
this.checkedNodes.splice(i, 1);
}
}
}
网友评论