You can add an object to the array with the method push
var lista = [{ id: 1, total: 50.00 }, { id: 2, total: 70.00 }];
lista.push({ id: 3, total: 50.00 });
But if you want to access the array quickly through id
you can use an object instead of array
itself.
var lista = {};
lista["1"] = { id: 1, total: 50.00 };
lista["3"] = { id: 3, total: 50.00 };
lista["5"] = { id: 5, total: 50.00 };
//Editando o valor do registro com id = 3
lista["3"].total = 300.00;
This is possible because a json object can be accessed similarly to a HashMap
(Java) or Dictionary
(C #), then json.Prop
is the same as json["Prop"]
.