SOURCE

function objectMerge(target, source) {
  if (typeof target !== 'object') {
    target = {}
  }
  if (Array.isArray(source)) {
    return source.slice()
  }
  Object.keys(source).forEach(property => {
    const sourceProperty = source[property]
    if (typeof sourceProperty === 'object') {
      target[property] = objectMerge(target[property], sourceProperty)
    } else {
      target[property] = sourceProperty
    }
  })
  return target
}

let obj1 = {
    name: "123",
    age: 23,
    address: "西柏坡1024号"
};
let obj2 =  {
    sex: "未知",
    height: "180cm"
};

console.log("合并以后的对象为: ", JSON.stringify(objectMerge(obj1, obj2)));
console 命令行工具 X clear

                    
>
console