把right的值赋值给left

let left = {a:1,b:3}
let right = {a:14,b:16,c:6}
function main(left,right){
    for(var i in left){
        if(right.hasOwnProperty(i)){
            left[i] = right[i]
        }
    }
    return left
}
console.log(main(left,right))


Object.entries(right).forEach(([key,value]) => { if(left.hasOwnProperty(key)){ left[key] = value } })
console.log(left)

 

posted @ 2020-08-21 11:26  石头记1  阅读(113)  评论(0编辑  收藏  举报