title: How to store and get a array cookie with Angular
body: <p>I need to push value in array and stored in  cookies when user click on GO button.</p>
  
  <p>if value is more than 10  i need to remove the first added item in the array and updated cookies , displayed in front end.</p>
  
  <p>but i'm tried multiple ways some time i am getting values sometimes not , the code is not consistently working.</p>
  
  <p>please find below the code </p>
  
  <p><strong>JS:</strong></p>
  
  <pre><code>$scope.lastorder = $cookies['lastorder'];
  
  $scope.cookiefunction=function(val) {
                  /*
                  $scope.lastorder.push(val);
                  if($scope.lastorder.length &gt; 4){
                          $scope.lastorder.shift();
                  }
                  $cookies.putObject('lastorder',$scope.lastorder);*/
  
  
                  $cookies['lastorder']={'productname':val};
                  $scope.lastorder = $cookies['lastorder'];
                  if($scope.lastorder.length &gt; 4){
                          $scope.lastorder.shift();
                  }
                  //$cookies['lastorder']={$scope.lastorder};
                  $scope.lastorder = $cookies['lastorder'];
          };
  </code></pre>
  
  <p><strong>in Frond end:</strong></p>
  
  <p>li ng-repeat="x in lastorder">{{x.productname}}</li></p>