模拟数据
let list = [
{
id: 0,
price: "4800",
name: "剑圣",
},
{
name:'赵信',
id:1,
price: "3600"
}
]
let list1 = [
{
id: 0,
price: "4800",
name: "剑圣",
},
{
name:'赵信',
id:1,
price: "3600"
},
{
id: 0,
price: "4800",
name: "Z7",
},
{
name:'锤石',
id:1,
price: "4800"
}
]
重复的保留一个
filter
let newData = list.concat(list2)
let dataFilter = newData.filter((item, index) => {
return newData.indexOf(item) === index
})
for
var arr = [];
let newData = list.concat(list1)
for(var i = 0; i < newData .length; i++){
if(arr.indexOf(newData [i])==-1){
arr.push(newData[i])
}
}
console.log(arr)
双数组比对重复的一个不留
for
L:for(let i=0;i<list.length;i++) {
for(let j=0;j<list1.length;j++){
if(list[i].name === list1[j].name) {
list[i].splice(i, 1)
i--
continue L //结束本次循环 没有结束全部循环
}
}
}
扩展资料:
属性 | 属性说明 | 使用说明 |
break | 用break语句可以使流程跳出switch语句体,也可以用break语句在循环结构终止本层循环体,从而提前结束本层循环。 | 1)只能在循环体内和switch语句体内使用break; (2)当break出现在循环体中的switch语句体内时,起作用只是跳出该switch语句体,并不能终止循环体的执行。若想强行终止循环体的执行,可以在循环体中,但并不在switch语句中设置break语句,满足某种条件则跳出本层循环体。 |
continue | continue语句的作用是跳过本次循环体中余下尚未执行的语句,立即进行下一次的循环条件判定,可以理解为仅结束本次循环。 | continue语句并没有使整个循环终止 |