2

I have User angular.forEach to push all the data and I have to remove all the data which I was pushed, So I used splice but it's not working. What I have to do instead of splice or is any method to remove all array.

Following is my code:

angular.forEach($scope.resourcedetails, function(resdata) {

          console.log(resdata);
          var removelength =   $scope.resourcedetails.length;
          $scope.adduser.push(resdata);
          console.log($scope.adduser.length);
          if (removelength >=0) {
          $scope.resourcedetails.splice(0, removelength)
          }


         });
Chirag Patel
  • 373
  • 5
  • 20
Vishnu
  • 725
  • 11
  • 30

1 Answers1

4

You can just assign an empty array to do this..

$scope.resourcedetails = [];

Take a look at this How do I empty an array in JavaScript?

Raghav
  • 1,001
  • 2
  • 14
  • 29