两个数组合并成一个数组

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/p930318/article/details/84790543

在post请求传参时body需要传数组对象,因此需要把两个参数数组对象合并。

求助同事后知道了笛卡尔积运算。

A:

aList:[{"memId":111},{"memId":222},{"memId":333}]

B:

bList:[{"name":"刘璐"},{"name":"张三"}]

C:(需要两个合并后的样子)

arrList:[{"memId":111,"name":"刘璐"},{"memId":222,"name":"张三"},{"memId":333}]

合并代码:

var ad=[];
var t=null;
this.aList.map(d=>{
   this.bList.map(b=>{
      t={};
      t.memId = b.memId;
      t.name = d.name;
      ad.push(t);
   })
              
})

传值:

JSON.stringify(ad)

猜你喜欢

转载自blog.csdn.net/p930318/article/details/84790543