title: How do I get variable unchanged in Angularjs
body: <p>Am trying to assign one variable value to another $scope variable (Or normal variable) in AngularJS script, and not modifying either of them after that. But I see both the variable values gets changed automatically - There is modification for some other variables after the above assignment.
  Why is my variables ("d" and "$scope.dataset_d_final") which are not being modified gets changed automatically?
  How can I prevent it?</p>
  
  <p>I have below AngularJS code</p>
  
  <pre><code>&lt;script&gt;
  var app = angular.module('ExampleApp', ['ui.plot']);
  app.controller('PlotCtrl', function ($scope) 
   {
      'use strict';
      $scope.sname = "Tttt";
      $scope.dataset_v = {
       "d0": { "id": 0, "name": "Housing", "value": 18 }, 
       "d1": { "id": 1, "name": "Travel", "value": 31.08 },
       "d2": { "id": 2, "name": "Restaurant", "value": 64 },
       "d3": { "id": 3, "name": "Bank", "value": 3 },
       "d4": { "id": 4, "name": "Movies", "value": 10 }
                         };
  
      $scope.dataset_final={};
  
      $scope.assign = function () 
      {
          var dataset=$scope.dataset_v;
          // Declare resulting empty array
  
          var d = [];
          // Get object keys and iterate over them
            Object.keys(dataset).forEach(function (key)  
            {
              // Get the value from the object
              var value = dataset[key].value;
              // Update values if in the range
              if(value &gt;= 10 &amp;&amp; value &lt;= 20) {
                 dataset[key].value = 7;
              } else if(value &gt; 20 &amp;&amp; value &lt;= 40) {
                 dataset[key].value = 8;
              }
               d.push(dataset[key]);
  
              $scope.dataset_d_final = d;  // THIS IS THE ASSIGNMENT
           // "$scope.dataset_d_final" and "d" variables gets changed even after performing no modification later in the code
  
  
               //  REVERSING
              var dataset1 = $scope.dataset_v;
              var d1 = [];
  
              Object.keys(dataset1).forEach(function (key) {
                  // Get the value from the object
                  var value = dataset1[key].value;
                  // Update values if in the range
                  if (value == 2) {
                      dataset1[key].value = 1;
                  } else if (value == 3) {
                      dataset1[key].value = 4;
                  }
                  d1.push(dataset1[key]);
              });
              alert('Final');
              alert(JSON.stringify($scope.dataset_d_final, null, 4));
              alert(JSON.stringify(d, null, 4));  // Both got changed as per above function
  
   });
  &lt;/script&gt;
  </code></pre>
  
  <p>My last alert for variables "d" and "$scope.dataset_d_final" should not be changed.. how can I do that ?</p>
  
  <p>I want to post either of d or $scope.dataset_d_final data to the server via $http service.</p>