小程序使用for...of遍历数据对象更新数据,代码示例如下:
words:[
{words:'哈',num:3,jilv:0},
{words:'口',num:8,jilv:0},
{words:'是',num:4,jilv:1},
{words:'了',num:3,jilv:5},
{words:'吗',num:0,jilv:5},
{words:'赛',num:2,jilv:3},
{words:'帮',num:1,jilv:2},
{words:'就',num:0,jilv:0},
],
words:"就"
//for of 不会修改原数组,可以创建一个新的数组保存到里面
var result=[]
for(let item of that.data.words){
if(item.words==that.data.wordss){
item.num+=1
}
result.push(item) //将更新的数组的push新创建的数组里面
var free=that.data.free
}
//更新数据
that.setData({
isshow:true,
words:result,
})