<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
var s1 = [{
id: 1,
name: '王贵'
},
{
id: 2,
name: '安娜'
}
]
var s2 = [{
id: 2,
name: '安娜1'
}]
const merge = (s1, s2) => {
const map = new Map()
for (let i = 0; i < s1.length; ++i) {
map.set(s1[i].id, s1[i].id).set(s1[i].name, s1[i].name)
console.log(s1);
console.log(map);
}
for (let i = 0; i < s2.length; ++i) {
console.log(map.has(s2[i].id));
console.log(map.has(s2[i].name));
}
return Array.from(map.values())
}
merge(s1, s2)
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
var List = [{
name: '王贵',
phone: '18225517585',
email: '15551245@qq.com',
province: '安徽省',
city: '合肥市',
district: '瑶海区',
address: '华润熙云府34302',
default: 0
},
{
name: '安娜',
phone: '18985623589',
email: '3596852455@qq.com',
province: '安徽省',
city: '合肥市',
district: '瑶海区',
address: '华润熙云府3302',
default: 0
}
]
var perload = {
name: '安娜',
phone: '18985623589',
email: '3596852455@qq.com',
province: '安徽省',
city: '合肥市1',
district: '瑶海区',
address: '华润熙云府3302',
default: 0
}
function aaa() {
let flag = false
List.forEach(v => {
for (var key in v) {
console.log(perload[key]);
if (v[key] != perload[key]) {
flag = true
return;
} else {
flag = false
}
}
})
if(flag) {
alert('添加')
}
}
aaa()
</script>
</body>
</html>