Javascript 角度2如何将对象数组放入另一个对象数组

Javascript 角度2如何将对象数组放入另一个对象数组,javascript,arrays,angular,typescript,object,Javascript,Arrays,Angular,Typescript,Object,所以我有两个数组总是相等的索引: 合并后的预期结果: A: [ {name: Jhon1, lastName: Pom1} {name: Jhon2, lastName: Pom2} {name: Jhon3, lastName: Pom3} ] Concat方法只是将整个数组合并到一个数组中,如下所示: A: [ {name: Jhon1} {name: Jhon2} {name: Jhon3} {lastName: Pom1}

所以我有两个数组总是相等的索引:

合并后的预期结果:

A: [
   {name: Jhon1, lastName: Pom1}
   {name: Jhon2, lastName: Pom2}
   {name: Jhon3, lastName: Pom3}
]
Concat方法只是将整个数组合并到一个数组中,如下所示:

  A: [
    {name: Jhon1}
    {name: Jhon2}
    {name: Jhon3}
    {lastName: Pom1}
    {lastName: Pom2}
    {lastName: Pom3}
    ]
我正在尝试的我自己的功能。下面有两个数组:this.prices和this.search.favoriteItems,我希望按照前面描述的相同方式合并它们:

showProducts(){
   for(let i of this.localStorageArray){
    let id = localStorage.getItem(i);
    this.search.getProductsById(id).subscribe
    ((data: any) => {
     this.prices.push(data.lowestPrices.Amazon);
     this.search.favoriteItems.push(data);  
   //something here to merge this.prices and this.search
    });

  }
  }
可以将.map与对象分解剪切一起使用:

设arr1=[{name:'Jhon1'},{name:'Jhon2'},{name:'Jhon3'}], arr2=[{lastName:'Pom1'},{lastName:'Pom2'},{lastName:'Pom3'}]; 设zip=a1,a2=>a1.mapo,i=>{…o,…a2[i]}; console.logziparr1,arr2; .as控制台包装{max height:100%!important;top:0;}您可以使用.map和对象析构图:

设arr1=[{name:'Jhon1'},{name:'Jhon2'},{name:'Jhon3'}], arr2=[{lastName:'Pom1'},{lastName:'Pom2'},{lastName:'Pom3'}]; 设zip=a1,a2=>a1.mapo,i=>{…o,…a2[i]}; console.logziparr1,arr2;
.作为控制台包装{max height:100%!important;top:0;}还感谢您提供CSS包装,我不知道您可以做到这一点!也谢谢你的CSS包装,我不知道你能做到!
showProducts(){
   for(let i of this.localStorageArray){
    let id = localStorage.getItem(i);
    this.search.getProductsById(id).subscribe
    ((data: any) => {
     this.prices.push(data.lowestPrices.Amazon);
     this.search.favoriteItems.push(data);  
   //something here to merge this.prices and this.search
    });

  }
  }