The following code successfully updates the values of a specific index in an array:
var pushTest = false
if(this.forUpdate.length == 0){
this.forUpdate.push(value);
}else{
for(var i=0;i<this.forUpdate.length;i++){
//check if the value id is existing in the array
if(value.item.id == this.forUpdate[i].item.id){
this.forUpdate.splice(this.forUpdate.indexOf(i), 1);
this.forUpdate.push(value);
pushTest = true
}
}
if(pushTest == false && this.forUpdate.length > 0){
this.forUpdate.push(value);
}
}
Observations:
First update
https://i.sstatic.net/IaWfD.png
Second update (same id as first update)
https://i.sstatic.net/Lf1z6.png
Third update (different id)
https://i.sstatic.net/1REw1.png
Everything seems to be working well, but upon updating again with id 1, all items with id 61 disappear from the array. The array only contains items with id 1 after the update. I want the updated item with id 1 to be included along with items having both id 1 and id 61 in the array. What am I missing here?