如何更新类星体中数组中存在的值



我声明数组为

const myproducts = ref([] )

之后,我将value压入数组。myproducts就像

[ { "id": 1, "qty": 1 }, { "id": 7, "qty": 1 } ]
var old_qty = myproducts.value.find(x => x.id === id).qty
var new_qty = old_qty +1

如何在id为1的数组中添加new_qty ?

TIA

var old_qty = myproducts.value.find(x => x.id === id).qty
var new_qty = old_qty +1
myproducts.value.find(x => x.id === id).qty = new_qty

myproducts.value.find(x => x.id === id).qty+=1;

相关内容

  • 没有找到相关文章

最新更新