JavaScript合并对象的2种写法
程序员文章站
2022-04-05 11:12:00
...
JavaScript合并对象的2种写法
第一种:
let obj1 = {a:"A"};
let obj2 = {b:"b"};
let obj3 = {b:"B",c:"C"};
let obj = Object.assign(obj1 ,obj2 ,obj3 );
console.log(obj) // {a:"A",b:"B",c:"C"}
第二种:
let obj1 = {a:"A"};
let obj2 = {b:"b"};
let obj3 = {b:"B",c:"C"};
let obj = {...obj1, ...obj2, ...obj3};
console.log(obj) // {a:"A",b:"B",c:"C"}
上一篇: AE虚线流动特效的动态字体怎么做? ae线条流动文字动画的实现方法
下一篇: js匿名函数的写法