<script>
const a =[
{id: "1", name: "a"},
{id: "2", name: "b"},
{id: "1", name: "c"}
]
const b =[
{id: "4", name: "q"},
{id: "3", name: "b"},
{id: "6", name: "c"}
]
const c = deleteRe(a,b)
console.log(c)
function deleteRe(a, b) {
//合并成一个数组
var c = a.concat(b),
// 用于id判断重复
temp = {},
//最后的新数组
result = [];
//遍历c数组,将每个item.id在temp中是否存在值做判断,
c.map((item, index) => {
if (!temp[item.id]) {
result.push(item);
temp[item.id] = true
}
})
return result
}
</script>
类数组对象去重(保持唯一id值)
最新推荐文章于 2022-05-09 15:46:07 发布