I have a problem with my Angular application where I need to add new elements to an array. The array is shown on the GUI after clicking a button.
Here is how my current array looks:
[ {name: 'user1', percentage: '1'} ]
But after clicking the button, I want the array to look like this:
[
{name: 'user1', percentage: '1'},
{name: 'user1', percentage: '0'}
]
The issue I'm facing is that adding another element changes every percentage to 0 like so:
[
{name: 'user1', percentage: '0'},
{name: 'user1', percentage: '0'}
]
This is the code for my array and the function to add a new element:
accData:any = [];
new(){
this.accData.push(this.accData[this.accData.length - 1]);
this.accData[this.accData.length - 1].percentage = '0';
console.log(this.accData)
}