-
幕布斯7119047
You can have few different approach to achieve this 1. using Map let tmp = [ {'id' : 'a', arr : [0,0,1]}, {'id' : 'b', arr : [1,0,1]}, {'id' : 'c', arr : [1,4,1]} ] var updated_array; updated_array = tmp.map(function(element){ if(element.id == 'a'){ return { id: element.id, arr : [3,0,1] } } else { return element } }) 2. Using Filter updated_array = tmp.filter(function(element){ if(element.id == 'a'){ return { id: element.id, arr : [3,0,1] } } else { return element }}) 3. Using ForEachtmp.forEach(function(element){ if(element.id == 'a'){ element.arr = [3,0,1] } }) 4. You can also use traditional while or for loop to achieve this
-
鸿蒙传说
像这样尝试let value =[ {'id' : 'a', arr : [0,0,1]}, {'id' : 'b', arr : [1,0,1]}, {'id' : 'c', arr : [1,4,1]} ] value.forEach(val=>{ if(val.id=='a'){ val.arr=[3,0,1] }})
-
杨魅力
您可以使用数组的 map() 并更新值。检查下面的代码。let tmp = [ {'id' : 'a', arr : [0,0,1]}, {'id' : 'b', arr : [1,0,1]}, {'id' : 'c', arr : [1,4,1]}]tmp.map(item =>{ if (item.id === 'a'){ item.arr=[3,0,1]; }})console.log(tmp);