将另一个对象添加到另一个对象中,并循环将数据输入进去。
代码示例:
const obj1 = { name: "Alice", age: 25 }; const obj2 = { address: "Beijing", phone: "123456" };
Object.assign(obj1, obj2); //将obj2合并到obj1中
for (const key in obj1) { //通过for…in循环将数据逐一输入进去 console.log(key, obj1[key]); }