get count of items with some property in an array

后端 未结 3 757
离开以前
离开以前 2020-11-29 11:19

I have an array of objects as follow.

$scope.students = [{\'isSelected\': true},
    {\'isSelected\': true},
    {\'isSelected\': false},
    {\'isSelected\':         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 11:26

    There is another way to do this: the AngularJS filters. You can write this:

    var selectedCount = $filter('filter')($scope.students, { isSelected: true }).length;
    

提交回复
热议问题