var arr1 = [
{a: "111", b:"222",c:1,d:6},
{a:"333", b:"444",c:11,d:56},
{a:"555", b: "666",c:21,d:46},
{a: "777", b:"888",c:13,d:36},
{a:"999", b:"000",c:14,d:26},
{a:"110", b: "220",c:51,d:16}
]
var arr2 = [
{a:"333", b:"444",c:11,d:56},
{a:"555", b: "666",c:21,d:46},
{a: "777", b:"888",c:13,d:36},
{a:"999", b:"000",c:14,d:26},
]
function removeList(originList, delList) {
var newArr = originList
delList.forEach((Element1, index1) => {
originList.forEach((Element2, index2) => {
if (isObjectValueEqual(Element1, Element2)) {
newArr.splice(index2, 1)
}
})
})
originList = newArr
return originList
}
function isObjectValueEqual(a, b) {
var aProps = Object.getOwnPropertyNames(a);
var bProps = Object.getOwnPropertyNames(b);
if (aProps.length != bProps.length) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
var propName = aProps[i]
var propA = a[propName]
var propB = b[propName]
if ((typeof (propA) === 'object')) {
if (this.isObjectValueEqual(propA, propB)) {
return true
} else {
return false
}
} else if (propA !== propB) {
return false
} else { }
}
return true
}
console.log(removeList(arr1,arr2));
// 不改变原数组的情况
console.log(removeList(JSON.stringify(arr1),arr2));
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。