Quote:The first time it is okay but on the next click function instead of adding the new object just to the next index of the array. It is also adding to the previous indexes.
In fact behind the hood, you push a pointer to object in array.
Next time, you push again a pointer to same object. And since array contain only pointers to 1 object, any change done to the object appear every where in the array.
To avoid this problem, you need to duplicate/copy the object before pushing in array.