get count of items with some property in an array

后端 未结 3 758
离开以前
离开以前 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:21

    You could also use javascript filter method (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)

    $scope.selectedStudentsCount = function() {
      return $scope.students.filter(function(obj){return obj.isSelected}).length;
    }
    

提交回复
热议问题