[{id:1,price:10},{id:2,price:20}]
How can I update the price to 200 for array of objects of id 2?
var obj = [{id:1,price:10},{id:2,price:20}];
for(var i=0;i<obj.length;i++){
if(obj[i].id == 2){
//what to do here?
}
}
I can proceed with push and splice etc but the challenge is to keep the position too.