js将数组对象里的元素进行改变并重新赋值

怎么把这种数据tempUser改成下面这种shopList,我改完发现重复了

tempUser:[
  0:{
goodsId: (...)
image: (...)
isStock: (...)
num: (...)
price: (...)
shopId: (...)
skuNames: (...)
spuId: (...)
stock: (...)
totalPrice: (...)
}
1:{
goodsId: (...)
image: (...)
isStock: (...)
num: (...)
price: (...)
shopId: (...)
skuNames: (...)
spuId: (...)
stock: (...)
totalPrice: (...)
}
]

    "shopList": [
        {
            "shopId": 1,
            "goodsList": [
                {
                    "goodsId": 1,
                    "spuList": [
                        {
                            "spuId": 1,
                            "num": 12
                        },
                        {
                            "spuId": 2,
                            "num": 10
                        }
                    ]
                },
                {
                    "goodsId": 3,
                    "spuList": [
                        {
                            "spuId": 10,
                            "num": 15
                        }
                    ]
                }
            ]
        },
        {
            "shopId": 2,
            "goodsList": [
                {
                    "goodsId": 1,
                    "spuList": [
                        {
                            "spuId": 1,
                            "num": 12
                        },
                        {
                            "spuId": 2,
                            "num": 10
                        }
                    ]
                },
                {
                    "goodsId": 3,
                    "spuList": [
                        {
                            "spuId": 10,
                            "num": 15
                        }
                    ]
                }
            ]
        }
    ]

我改的——

 this.tempUser.map(item => {
            const obj2 = {
              spuId: item.spuId,
              num: item.num
            }
            this.arr2.push(obj2)
          })
          console.log('tempUser', this.tempUser)//ok
            var good = this.tempUser.map(o => o.goodsId === this.tempUser[0].goodsId);
            var type = good[good.length - 1]
            console.log('good', type)
          // goodsList
          if (type === true) {
            //不同规格
            this.tempUser.map(item => {
              const newOut1 = {
                goodsId: item.goodsId,
                spuList: this.arr2
              }
              this.goodsList.push(newOut1)
            })
          } else {
            //不同商品
            for (var i = 0; i < this.tempUser.length; i++) {
              const newOut1 = {
                goodsId: this.tempUser[i].goodsId,
                spuList: [this.arr2[i]],
              }
              this.goodsList.push(newOut1)
            }
          }
            this.goodsList = this.deletefunc1(this.goodsList);
    console.log('goodsList',this.goodsList)
            this.tempUser.map(item => {
              const newOut = {
                shopId: item.shopId,
                goodsList: this.goodsList
              }
              this.tempList.push(newOut)
            })
            this.tempList = this.deletefunc(this.tempList);
deletefunc1(arrayList) {
        const res = new Map();
        return arrayList.filter((arrayList) => !res.has(arrayList.goodsId) && res.set(arrayList.goodsId, 1)); //过滤
      },
      deletefunc(arrayList) {
        const res = new Map();
        return arrayList.filter((arrayList) => !res.has(arrayList.shopId) && res.set(arrayList.shopId, 1)); //过滤
      },
效果——
[0:{
goodsList: Array(2)
shopId: 1
},1{
goodsList: Array(2)
shopId: 2}
]

OK解决

1————
    for (var i = 0; i < this.tempUser.length; i++) {
                            const newOut1 = {
                                goodsId: this.tempUser[i].goodsId,
                                spuList: [this.arr2[i]],
                            }
                            this.goodsList.push(newOut1)
                        }
                    } else {
                        //不同商品
2————
for (var i = 0; i < this.tempUser.length; i++) {
                        const newOut = {
                            shopId: this.tempUser[i].shopId,
                            goodsList: [this.goodsList[i]],
                        }
                        this.tempList.push(newOut)
                    }