vara1=[{path:'home'},{path:'index'}]vara2=[{path:'home'},{path:'index'},{path:'delpage'}]两个数组循环,删除不同的对象元素期望a2=[{path:'home'},{path:'index'}]
1 回答
慕村9548890
TA贡献1884条经验 获得超4个赞
let leftData = [1,2,3,4,5] //原数组
let targetKeys = [3,5] //要删除的元素
let rightData = [6,7] //最终需要的数组
let leg = this.leftData.length
for (let i = leg - 1; i >= 0; i--) {
for (let j = 0; j < targetKeys.length; j++) {
if (leftData[i]) {
if (leftData[i] == targetKeys[j]) {
rightData.push(leftData[i])
leftData.splice(i, 1)
continue; //结束当前本轮循环,开始新的一轮循环
}
}
}
}
添加回答
举报
0/150
提交
取消