想请教下,关于一个数组对象的操作,谢谢大家?

作者站长头像
站长
· 阅读数 15

this.shop_datathis.shop_data_storage

我有上面两个数组对象,他们里面都共有一个属性名is_selector_val,

我想把this.shop_data_storage 的 每项里的is_selector_val 的值 赋值给this.shop_data的每项里的is_selector_val

请问如何去写?我目前能想到的 就是类似下面这种思路

this.shop_data.map(item1=>{

this.shop_data_storage.map(item2=>{
    item1.is_selector_val = item.is_selector_val
})

})

这样好像也不行,只能去改变this.shop_data 原数组对象,而不能去赋新值,因为我这是搜索结果里的数据

回复
1个回答
avatar
test
2024-07-17
this.shop_data.forEach((item, index) => {
    item.is_selector_val = this.shop_data_storage[index]?.is_selector_val;
})
回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容