In my programming task, I am working with an object and an array that are defined as follows:
$scope.multipleTransferGotten = [];
$scope.newParameters = {
UserId: "",
Udid:"",
TransType: "",
SourceAccNumber: "",
SourceAccName:"",
BeneficiaryAccName: "",
BeneficiaryAccNumber: "",
Amount: "",
Remarks: "",
DestBankCode:"",
AuthToken:"",
UseToken: ""
};
There is a specific line of code in my script that retrieves an array from the session storage;
$scope.pickedTransfers = bank.getPaymentList($scope.paymentList);
What I need to achieve is to iterate through each element of the array obtained from the session and assign its values to $scope.newParamaters before pushing them into the $scope.multipleTransferGotten array. Here's how it looks like:
for (var i = 0; i < $scope.pickedTransfers.length; i++)
{
$scope.newParameters.UserId = bank.getUserId();
$scope.newParameters.Udid = bank.getUuid();
$scope.newParameters.TransType = $scope.pickedTransfers[i].TransType;
$scope.newParameters.SourceAccNumber = $scope.pickedTransfers[i].SourceAccNumber;
$scope.newParameters.SourceAccName = bank.getAccountInfo()[i].CUSNAME;
$scope.newParameters.BeneficiaryAccName = $scope.pickedTransfers[i].BeneficiaryAccName;
$scope.newParameters.BeneficiaryAccNumber = $scope.pickedTransfers[i].BeneficiaryAccNumber;
$scope.newParameters.Amount = $scope.pickedTransfers[i].Amount;
$scope.newParameters.Remarks = $scope.pickedTransfers[i].Remarks;
$scope.newParameters.DestBankCode = $scope.pickedTransfers[i].DestBankCode;
$scope.newParameters.AuthToken = $localStorage.AuthToken;
$scope.newParameters.UseToken = bank.getUseToken();
$scope.multipleTransferGotten.push($scope.newParameters);
}
However, I'm encountering an issue where only the last index in the array populates the $scope.multipleTransferGotten array. Essentially, if I loop through 2 arrays, only the data from $scope.pickedTransfers[1] is stored twice in $scope.multipleTransferGotten.
I seek assistance in resolving this issue so that both $scope.pickedTransfers[0] and $scope.pickedTransfers[1] can be properly read, assigned, and stored in the $scope.multipleTransferGotten array. Thank you for your help.