0

I'm trying to push some items into an array but for simplicity sake I'm using the following code as an example. filterObj is an empty object but when pushed onto array filterArr, filterArr contains [{}]. I tried to put in a if condition:

if(filterObj != {}) {
    $scope.filterArr.push(filterObj);
}

The above if condition doesn't work because the output still turns out to be [{}]

Code :

<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
function MyCtrl($scope) {
    $scope.lines = [];

    $scope.filterArr = [];
    var filterObj = new Object();
    filterObj = {};
    $scope.filterArr.push(filterObj);

    $scope.addLine = function () {
        $scope.lines.push($scope.lines.length);
    };
}
</script>
</head>
<body>
  <div ng-app ng-controller="MyCtrl">
    <button ng-click="addLine()">Run</button>
    <div ng-repeat="line in lines">
        FilterArr : {{filterArr}}.
    </div>
</div>
</body>
</html>

What I would like to see is that when filterArr is output, it should show [] instead of [{}] Thanks for your help!

Nikhil Hegde
  • 341
  • 1
  • 3
  • 15

0 Answers0