3 回答
TA贡献2041条经验 获得超4个赞
你的意思是这样?
使用地图、索引和传播作为:
let a = [
{name:"xyz",id:123 },
{name:"abc",id:232},
]
let b = [
{value:'anyrhing'},
{value:'anything12312'}
]
let res = a.map((el,idx)=> ({...el,...b[idx]}));
console.log(res)
TA贡献1817条经验 获得超14个赞
使用对象解构。
const arr1 = [
{name:'xyz',id:123 },
{name:'abc',id:232},
]
const arr2 = [
{value:'anyrhing'},
{value:'anything12312'}
]
const arr3 = [];
for(let i=0;i<arr1.length;i++)
arr3.push({...arr2[i],...arr1[i]});
TA贡献1828条经验 获得超13个赞
A1=[
{name:"xyz",id:123 },
{name:"abc",id:232},
];
A2=[
{value:'anyrhing'},
{value:'anything12312'}
];
obj1={
...A2[0],
...A1[0]}
//another method to merge objects
obj2=Object.assign(A2[1],A1[1]);
//The result you needed
A3=[obj1,obj2];
添加回答
举报