I am facing an issue with two variables in my code. Whenever I update one variable, the other variable also gets updated automatically. Can someone please help me understand what is causing this behavior?
$scope.pages = [];
$scope.pagesSave = [];
var functionName = function(){
$service.doThing1().then(function(res1){
$scope.pagesSave = res1;
console.log(res1)
$service.doThing2().then(function(res2){
$scope.pages = $service.formatThings(res2, res1);
console.log($scope.pages)
}, function(err){});
}, function(err){});
The expected result is for $scope.pages to store the final formatted data.
Similarly, $scope.pagesSave should contain the unformatted data.
However, when I check these variables using console logs, they appear to be identical.
Interestingly, the console log immediately after executing $service.doThing1() shows that "res1" has the correct length but only contains the data from $scope.pages, which can be seen in this image:
In the console log, 2 pieces of data are missing even before the formatting function is applied.
https://i.sstatic.net/2XJBA.png
If anyone knows why this is happening, your insights would be greatly appreciated.
For reference, I am using Chrome to view the console logs.