[{name:"0100000000000001",value:"1"},{name:"0100000000000000",value:"4"}]
请问这种json数组,怎么依据条件加入其他数据,比如,当value=1时,加入a=2;当value=4时,a=1,
变成[{name:"0100000000000001",value:"1",a:"2"},{name:"0100000000000000",value:"4",a:"1"}]
[{name:"0100000000000001",value:"1"},{name:"0100000000000000",value:"4"}]
请问这种json数组,怎么依据条件加入其他数据,比如,当value=1时,加入a=2;当value=4时,a=1,
变成[{name:"0100000000000001",value:"1",a:"2"},{name:"0100000000000000",value:"4",a:"1"}]
let arr=[{name:"0100000000000001",value:"1"},{name:"0100000000000000",value:"4"}]
for(var i in arr){
if(arr[i].value==1){
arr[i].a=2
}
else if(arr[i].value==4){
arr[i].a=1
}
}
console.log(arr);
结果如下: