0

if i have simple object like this:

$scope.results = {
  year:2021,
  subjects:[
    {title:'English',grade:'A'},
    {title:'Maths',grade:'A'},
    {title:'Science',grade:'B'},
    {title:'Geography',grade:'C'}
  ]
};

IT IS NO PROBLEM to get value using filter, like here

 $scope.gradeC = $filter('filter')($scope.results.subjects, {grade: 'C'})[0];

or count it :

 $scope.gradeA = $filter('filter')($scope.results.subjects, {grade: 'A'}).length;

BUT, if i have something like this:

$scope.results = {
  year:2021,
  subjects:[
    {title:'English',grade:''},
    {title:'Maths',grade:''},
    {title:'Science',grade:''},
    {title:'Geography',grade:'{
                 _someDate : 'Nov 19, 2024'
             }'}
  ]
};

how could i to count how much values in grade with empty string i have and how much with some Object as value?

1 Answer 1

2

A filter is useful in the view. But in the JS code, you have all the power of standard JS functions with you:

var countWithEmptyGrade = $scope.results.subjects.filter(function(subject) {
    return subject.grade === '';
}).length;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.