The reason for this issue is due to the initial assignment of the pointer to
this.selectedVoucher.approvalStepList
at the start of the code:
this.approvalStepList = this.selectedVoucher.approvalStepList; // not sorted
Instead, it would be better to assign a copy of the array using the spread operator like this:
this.approvalStepList = [...this.selectedVoucher.approvalStepList];
The problem arose because without making a clone, but only assigning a variable, both values were linked together as they referenced the same object in memory. Any changes made to one would affect the other. By creating a copy, this issue can be resolved. Here's a simple example to explain this:
https://i.sstatic.net/tjLbH.png